自定义搜索栏搜索图标

时间:2013-12-17 06:11:11

标签: ios ios7 uisearchbar

我正在使用此自定义搜索栏,但它没有显示任何图像。它也会删除默认图像。

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;

    }

1 个答案:

答案 0 :(得分:1)

试试这个:

[workLocationSearchBar setImage:[UIImage imageNamed:@"IMAGE_NAME"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];