UISearchController的cancel按钮自定义中文取消

转载的
iOS13 UISearchBar的层级发生了变化
UISearchController的cancel按钮自定义中文取消
文章图片
iOS13 中取消了私有KVC
【UISearchController的cancel按钮自定义中文取消】其中UISearchBar
[searchBar setValue:@"xxx "forKey:@"_cancelButtonText"];
一旦命中就crash
将cancel设为中文“取消”方法如下
self.searchController.searchBar.showsCancelButton = YES;
NSArray*searchBarSubViews = [self.searchController.searchBarsubviews]; //UIView
UIView*view = [searchBarSubViewsobjectAtIndex:0];
NSArray*searchBarContainerView = [[[viewsubviews]objectAtIndex:1] subviews]; //UISearchBarContainerView
for(UIView*viewinsearchBarContainerView) {
if ([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
UIButton*cancelButton = (UIButton*)view;
[cancelButtonsetTitle:@"取消"forState:UIControlStateNormal];
}
}
注意:一定要提前把showsCancelButton 设置为YES,否则UISearchBarContainerView第一次的subviews没有UINavigationButton
0人点赞
日记本
作者:花田半亩1992
链接:https://www.jianshu.com/p/f6054c965480
来源:
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    推荐阅读