这里需要注意里面的那个setShowCancelButton:YES 才行
//自定义搜索取消button title
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
[_searchBar setShowsCancelButton:YES animated:NO];
UIView *topView = controller.searchBar.subviews[0];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
UIButton *cancelButton = (UIButton*)subView;
[cancelButton setTitle:GDLocalizedString(@"cancel") forState:UIControlStateNormal]; //@"取消"
}
}
}
本文介绍如何在iOS应用中使用Objective-C自定义UISearchDisplayController中的搜索取消按钮,并展示具体的实现代码。通过覆盖默认的取消按钮标题,开发者可以更好地适配应用UI风格。
4272

被折叠的 条评论
为什么被折叠?



