首页 > 移动平台 > 详细

IOS 改变UISearchBar的背景色

时间:2016-01-27 12:34:19      阅读:144      评论:0      收藏:0      [点我收藏+]

之前网上提供的方法试了很多种  都不能很好的去掉背景色  ,修改背景色方法如下:

 

searchbar.barStyle = UIBarStyleBlackTranslucent;

    searchbar.autocorrectionType = UITextAutocorrectionTypeNo;

    searchbar.autocapitalizationType = UITextAutocapitalizationTypeNone;

    searchbar.keyboardType = UIKeyboardTypeDefault;

searchbar.backgroundImage = [self SearchImageWithColor:[UIColor clearColor] size:searchbar.bounds.size];
 
定义一个函数  
//取消searchbar背景色
- (UIImage *)SearchImageWithColor:(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;
}

IOS 改变UISearchBar的背景色

原文:http://www.cnblogs.com/seer/p/5162509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!