Reputation: 7746
I have a UITextFiled added to a view in Xcode 5.1, I am trying to add image to its left view using code below however when I run all I don't see the image , don't understand the reason , please help
UIImageView *imgView = [[UIImageView alloc] init];
imgView.image = [UIImage imageNamed:@"Key.png"];
[txtCode setLeftViewMode:UITextFieldViewModeAlways];
[txtCode setLeftView:imgView];
Upvotes: 0
Views: 166
Reputation: 1421
Hope this will help you...Add image in paddingView if you want.
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
self.textFiled.leftView = paddingView;
self.textFiled.leftViewMode = UITextFieldViewModeAlways;
Upvotes: 1
Reputation: 2189
Set the Frame for the Image View:
yourTextField.borderStyle = UITextBorderStyleNone;
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
imgView.image = [UIImage imageNamed:@"Key.png"];
[yourTextField setLeftViewMode:UITextFieldViewModeAlways];
[yourTextField setLeftView:imgView];
Upvotes: 1