我想在SearchBar中更改Scope Bar的ScopeBarButton的backGround颜色。 如何更改它如下所示。
[红] [橙] [黄色] [绿色] [蓝色] [紫]
告诉我......答案 0 :(得分:0)
您只能更改整个searchBar的颜色,而不能仅更改scopeButton。但是你可以选择为范围栏设置背景* 图像 *:
[searchBar setScopeBarBackgroundImage:[UIImage imageNamed:@"bg.jpg"]];
答案 1 :(得分:0)
您可以先绘制渐变,获取图像,然后使用ABros所说的设置backgroundImage:
UIGraphicsBeginImageContext(scopeBar.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor, (id)[UIColor orangeColor].CGColor, (id)[UIColor yellowColor].CGColor, (id)[UIColor greenColor].CGColor, (id)[UIColor blueColor].CGColor, (id)[UIColor purpleColor].CGColor, nil];
CGFloat locations[6] = {0.0,0.2,0.4,0.6,0.8,1.0};
CGGradientRef gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), (__bridge CFArrayRef)colors, locations);
CGContextDrawLinearGradient(context, gradient, CGPointZero, CGPointMake(scopeBar.size.width, 0), nil);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[searchBar setScopeBarBackgroundImage:image];