Set the image to the right of UITextField in iOS and complete UITextField Solution
Effect:
Encapsulated method:
A small encapsulated method is shared to facilitate code copy in the future. If you have better suggestions, you can tell me that object-oriented is a large project, but we are on the road.
/*** Set the image to the right of UITextField ** @ param textField UITextField * @ param imageName image name */-(void) setRightViewWithTextField :( UITextField *) textField imageName :( NSString *) imageName {UIImageView * rightView = [[UIImageView alloc] init]; rightView. image = [UIImage imageNamed: imageName]; rightView. size = CGSizeMake (40, 40); rightView. contentMode = UIViewContentModeCenter; textField. rightView = rightView; textField. rightViewMode = UITextFieldViewModeAlways ;}
Call:
-(Void) viewDidLoad {[super viewDidLoad]; [self setRightViewWithTextField: self. userNameTextField imageName: @ "zc01"]; [self setRightViewWithTextField: self. passwordTextField imageName: @ "zc02"];}