UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
imagev.image = [UIImage imageNamed:@""];
imagev.contentMode = UIViewContentModeCenter;
UITextField *txtSearch = [[UITextField alloc] init];
txtSearch.leftView = imagev;
txtSearch.leftViewMode = UITextFieldViewModeAlways;
这是以往设置leftView的方法,但是在iOS13下,发现是无效的,解决的方法很简单,将UIImageView改为UIView即可:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UITextField *txtSearch = [[UITextField alloc] init];
txtSearch.leftView=view;
txtSearch.leftViewMode = UITextFieldViewModeAlways;
网友评论