将左视图设置为TextField的底部

时间:2018-08-15 11:19:49

标签: ios swift uitextfield

我想将Leftview设置为TextField。但我想将其与Textfield的底部对齐。使左视图框架看起来与TextField实际文本对齐。但是我没有任何运气。

这是我尝试的方式。

let btnSelectCountry = UIButton()
btnSelectCountry.setTitle(title, for: UIControlState.normal)

btnSelectCountry.titleEdgeInsets = UIEdgeInsetsMake(0, 0, -10, 0)

btnSelectCountry.backgroundColor = CommonUtils.hexStringToUIColor(hex: "#000000")
btnSelectCountry.frame = CGRect(x: 0, y: CGFloat(0), width: CGFloat(70), height: CGFloat(25))
btnSelectCountry.addTarget(self, action: #selector(self.selectCountryCallingCode), for: .touchUpInside)
etPhoneNum.leftView = btnSelectCountry
etPhoneNum.leftViewMode = .always
etPhoneNum.leftViewRect(forBounds: CGRect(x: 0, y: CGFloat(-100), width: CGFloat(70), height: CGFloat(25)))

但是它在TextField中显示为垂直对齐。如何将LeftView移到TextField的底部?

1 个答案:

答案 0 :(得分:0)

   func setTextLeftView(){

        txtField.leftView = UIImageView.init(image: image)
        txtField.leftView?.frame = CGRect(x: 0, y: 5, width: 20 , height:20)
        txtField.leftViewMode = .always

    }

尝试一下,如果对您不起作用,请告诉我是否想解决您的问题:)