美文网首页
UISearchBar的一些相关设置

UISearchBar的一些相关设置

作者: BigBossZhu | 来源:发表于2017-01-03 09:40 被阅读11次

barTintColor

1. 获取到UISearchBar 中的searchField

UITextField *searchField = [searchBar valueForKey:@"searchField"];
可以进行设置

2. 更改searchBar的searchField外部的颜色.利用绘图获取.

_searchBar.backgroundImage = [self imageWithColor:[UIColor colorWithHexString:@"F4F5F7"] size:_searchBar.bounds.size];

//取消searchbar背景色
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

相关文章

网友评论

      本文标题:UISearchBar的一些相关设置

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