iOS searchbar的背景颜色怎么改成透明
程序员文章站
2022-06-22 18:50:10
iOS searchbar的背景颜色怎么改成透明。
//搜索条的背景色
self.search.backgroundImage = [self imageWithCol...
iOS searchbar的背景颜色怎么改成透明。
//搜索条的背景色 self.search.backgroundImage = [self imageWithColor:[UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:0] size:_search.bounds.size]; - (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; }