美文网首页iOSiOS UI
iOS11的UISearchBar适配

iOS11的UISearchBar适配

作者: 修正 | 来源:发表于2017-09-25 09:35 被阅读1553次

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

相关文章

网友评论

    本文标题:iOS11的UISearchBar适配

    本文链接:https://www.haomeiwen.com/subject/czduhttx.html