ios - UiTextField leftViewMode odd Behavior.. Bug? -
i have 2 textfields
, in each textfield
want put icon in leftimageview
. when attempt load view, ui gets hung , never loads. if comment out 1 of tag blocks. ui loads fine , end textfield icon in leftview.
my issue getting icon in both textfields.
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 } }
try this
@iboutlet var collectionoftextfields: array<uitextfield>? 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 }
let me know if need how add textfields collection.
hope helps.
Comments
Post a Comment