[[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;
}
這里設(shè)置了背景的顏色和字體火的,與之前的樣式一致丧蘸;
解決了UISearchBar添加在UINavigationBar 上面的時候,pushVC踏枣,然后pop之后字體變大的問題渠鸽。