2

我想在 SearchBar 中更改 ScopeBar 的 ScopeBarButton 的 backGroundColor。我该如何改变它,如下所示。

[红][橙][黄][绿][蓝][紫]

告诉我...

4

2 回答 2

0

您只能更改整个 searchBar 的颜色,而不能仅更改 scopeButton。但是您确实可以选择为您的范围栏设置背景*图像*:

[searchBar setScopeBarBackgroundImage:[UIImage imageNamed:@"bg.jpg"]];
于 2012-07-10T01:49:09.703 回答
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];
于 2012-07-10T02:04:06.773 回答