iOS 通过设置颜色去除UISearchBar的灰色背景
2016-12-23 16:27
591 查看
实现效果前:
实现效果后:
实现代码如下:
@property (weak,
nonatomic) IBOutlet
UISearchBar *searchbar;
通过UIImage* searchBarBg;调用下面的代码
UIImage* searchBarBg = [self GetImageWithColor:[UIColor
clearColor]
andHeight:32.0f];
[self.searchbar
setBackgroundImage:searchBarBg];
#pragma mark 实现搜索条背景透明化
- (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height{
CGRect r=
CGRectMake(0.0f,
0.0f, 1.0f, height);
UIGraphicsBeginImageContext(r.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color
CGColor]);
CGContextFillRect(context, r);
UIImage *img =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
通过这些便实现了去除UISearchBar的灰色背景
实现效果后:
实现代码如下:
@property (weak,
nonatomic) IBOutlet
UISearchBar *searchbar;
通过UIImage* searchBarBg;调用下面的代码
UIImage* searchBarBg = [self GetImageWithColor:[UIColor
clearColor]
andHeight:32.0f];
[self.searchbar
setBackgroundImage:searchBarBg];
#pragma mark 实现搜索条背景透明化
- (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height{
CGRect r=
CGRectMake(0.0f,
0.0f, 1.0f, height);
UIGraphicsBeginImageContext(r.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color
CGColor]);
CGContextFillRect(context, r);
UIImage *img =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
通过这些便实现了去除UISearchBar的灰色背景
相关文章推荐
- IOS开发代码分享之设置UISearchBar的背景颜色
- iOS开发问题——UISearchBar背景颜色去除问题
- 如何去除UISearchBar默认的灰色背景颜色
- Flex Gumbo中如何通过baseColor样式,设置FxHScrollBar背景颜色
- ios7 下设置UISearchBar背景 去除底部线条
- IOS UINavigationBar 背景及按钮颜色设置
- iOS设置UISearchBar光标的颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- 自定义UISearchBar 适配IOS6和IOS7 修改放大镜图标 修改光标颜色 修改边框颜色 placeholder颜色 设置文本框背景
- ios-设置UISearchBar输入框的颜色等属性
- iOS UISearchBar的背景颜色修改
- 芒果iOS开发之通过RGB值设置背景颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- ios开发之--调整UISearchBar的输入框的背景颜色
- iOS开发设置UISearchBar的输入背景框、提示文字等
- iOS更改UISearchBar里面的UITextField的frame以及去除UISearchBar的背景
- ios7 下设置UISearchBar背景 去除底部线条
- iOS 关于searchbar的背景颜色的设置
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- iOS UISearchBar的背景框颜色适应