gpt4 book ai didi

ios - UiTextField leftViewMode 奇怪的行为.. Bug?

转载 作者:行者123 更新时间:2023-11-30 13:29:35 26 4
gpt4 key购买 nike

我有两个 textFields,在每个 textField 中我想在 leftImageView 中放置一个图标。当我尝试加载此 View 时,用户界面会挂起并且永远不会加载。如果我注释掉其中一个标签 block 。我的 UI 加载良好,最终在左侧 View 中出现一个带有图标的文本字段。

我的问题是在两个文本字段中都获得一个图标。

    for textField in textFields {
textField.delegate = self
textField.autocorrectionType = .No
textField.leftViewMode = .Always

if textField.tag == 1 {
textField.keyboardType = .EmailAddress
textField.attributedPlaceholder = attributedText("Username")

leftImageViews[0].image = UIImage(named: "user")
leftImageViews[0].contentMode = .ScaleAspectFit
leftTextFieldViews[0].addSubview(leftImageViews[0])
textField.leftView = leftTextFieldViews[0]
textField.leftView?.frame = leftTextFieldViews[0].frame

} else if textField.tag == 2 {
textField.secureTextEntry = true
textField.attributedPlaceholder = attributedText("Password")

leftImageViews[1].image = UIImage(named: "password")
leftImageViews[1].contentMode = .ScaleAspectFit
leftTextFieldViews[1].addSubview(leftImageViews[1])
textField.leftView = leftTextFieldViews[1]
textField.leftView?.frame = leftTextFieldViews[1].frame

}
}

最佳答案

试试这个

 @IBOutlet var collectionOftextfields: Array<UITextField>?

for i in 0 ..< collectionOftextfields!.count {
let textfieldimage = UIImageView()
let image = UIImage(named: "xyz.png")
textfieldimage.image = image
textfieldimage.frame = CGRect(x: 0,y: 200,width: 8,height: 8)
var myField = UITextField()
myField = collectionOftextfields![i]
myField.leftView = textfieldimage
myField.leftViewMode = UITextFieldViewMode.Always
}

如果您需要有关如何将文本字段添加到集合中的帮助,请告诉我。
希望这会有所帮助。

关于ios - UiTextField leftViewMode 奇怪的行为.. Bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36731972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com