[[UISearchBar appearance] setSearchFieldBackgroundImage:[self __searchFieldBackgroundImage] forState:UIControlStateNormal];
UITextField*textField = [UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class],[UINavigationBar class]]];
[textField setDefaultTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
- (UIImage*)__searchFieldBackgroundImage {
UIColor*color = BXS_F2_F2_F2_COLOR;
CGFloatcornerRadius = 3;
CGRectrect =CGRectMake(0,0,28,28);
UIBezierPath*roundedRect = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius];
roundedRect.lineWidth=0;
UIGraphicsBeginImageContextWithOptions(rect.size,NO,0.0f);
[color setFill];
[roundedRect fill];
[roundedRect stroke];
[roundedRect addClip];
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这里设置了背景的颜色和字体,与之前的样式一致;
解决了UISearchBar添加在UINavigationBar 上面的时候,pushVC,然后pop之后字体变大的问题。