更改UISearchBar button属性

//点击搜索框时触发

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar

{

    self.theSearchUserSearchBar.showsCancelButton = YES; //很关键

    

    UIView *topView = self.theSearchUserSearchBar.subviews[0];

    

    for (UIView *searchbuttons in topView.subviews)

    {

        if ([searchbuttons isKindOfClass:NSClassFromString(@"UINavigationButton")])//NSClassFromString(@"UINavigationButton")

        {

            UIButton *cancelButton = (UIButton*)searchbuttons;

            cancelButton.enabled = YES;

            [cancelButton setTitle:@"确定" forState:UIControlStateNormal];

            break;

        }

    }

 

 

    

    return YES;

}

 

所以,同理可以更改 UISearchBar上面的任意view。

 

posted @ 2014-11-06 10:42  天牛  阅读(257)  评论(0编辑  收藏  举报