有关UISearchBar 去除背景。适配IOS6与IOS7

 

IOS 7 下:

[searchBar setBarTintColor:[UIColor clearColor]];//可用(方法一)

 

 

(方法二)在没有提供背景图的情况下的解决方法。

searchBar.backgroundImage = [self imageWithColor:[UIColor clearColor]];
 
- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
     
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
     
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
     
    return image;
}
posted @ 2014-05-16 17:04  夜深人未静  阅读(58)  评论(0)    收藏  举报