轉(zhuǎn)載的
iOS13 UISearchBar的層級發(fā)生了變化
iOS13 中取消了私有KVC
其中UISearchBar
[searchBar setValue:@"xxx "forKey:@"_cancelButtonText"];
一旦命中就crash
將cancel設(shè)為中文“取消”方法如下
? ? 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 設(shè)置為YES柑蛇,否則UISearchBarContainerView第一次的subviews沒有UINavigationButton
0人點贊
作者:花田半畝1992
鏈接:http://www.reibang.com/p/f6054c965480
來源:簡書
著作權(quán)歸作者所有跺涤。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)劲阎,非商業(yè)轉(zhuǎn)載請注明出處苛败。