首页 > 代码库 > 更改UISearchBar button属性

更改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。

 

更改UISearchBar button属性