UITextField within UISearchBar in iOS 7

后端 未结 7 1688
北荒
北荒 2020-12-16 01:00

I am trying to accomplish the same look of my UISearchBar with a TextField within it, as in my iOS 6 app. I have tried to code it in several ways and not yet been successful

7条回答
  •  清歌不尽
    2020-12-16 01:23

    in iOS 7 to access Text Field you have to reiterate on level more. Change your code like this

    for (UIView *subView in self.searchBar.subviews){
        for (UIView *ndLeveSubView in subView.subviews){
        if ([ndLeveSubView isKindOfClass:[UITextField class]])
            {
                searchBarTextField = (UITextField *)ndLeveSubView;
                break;
            }
        }
       }
    

    But best way to clear backgournd of UISearchBar and setting searchbar icon in text field is:

    [searchBar setBackgroundImage:[[UIImage alloc] init] ];//if you want to remove background of uisearchbar
    UIImage *image = [UIImage imageNamed: @"search_icon.png"];
    [searchBar setImage:image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    

提交回复
热议问题