iOS11的UISearchBar适配

[[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之后字体变大的问题。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容