Add image to UITextField in Xcode? Add image to UITextField in Xcode? xcode xcode

Add image to UITextField in Xcode?


UITextField has a rightView property, if you have image like this- enter image description here then You can easly set ImageView object to rightView:

UITextField *myTextField = [[UITextField alloc] init];myTextField.rightViewMode = UITextFieldViewModeAlways;myTextField.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"downArrow.png"]];


In Swift:

textField.leftViewMode = UITextFieldViewMode.AlwaystextField.leftView = UIImageView(image: UIImage(named: "imageName"))


You can put the UIImageView to the left of your UITextField.

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(96, 40, 130, 20)];[textField setLeftViewMode:UITextFieldViewModeAlways];textField.leftView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchIccon.png"]];