大家有没有遇到searchBar的取消按钮会出现特别小的情况,初次发现这种情况是在iOS10上,不过下边这种解决办法亲测不限系统
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES];
for(id view in [searchBar.subviews[0] subviews])
{
if([view isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)view;
btn.titleLabel.font = [UIFont systemFontOfSize:16];
[btn setContentEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)]; //解决iOS10上按钮太小的问题
btn.titleLabel.adjustsFontSizeToFitWidth = YES;
}
}
}