我正在使用此自定义搜索栏,但它没有显示任何图像。它也会删除默认图像。
UITextField *searchField = nil;
for (UIView *subview in [[workLocationSearchBar.subviews lastObject] subviews]) {
NSLog(@"hey");
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
NSLog(@"inside");
break;
}
}
if (searchField) {
UIView *searchIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"circle.png"]];
if ([searchIcon isKindOfClass:[UIImageView class]]) {
}
NSLog(@"aye");
searchField.rightView = searchIcon;
searchField.leftView=searchIcon;
}
答案 0 :(得分:1)
试试这个:
[workLocationSearchBar setImage:[UIImage imageNamed:@"IMAGE_NAME"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];