【问题标题】:ScopeBar in SearchBarSearchBar 中的 ScopeBar
【发布时间】:2012-10-13 14:53:42
【问题描述】:

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

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

告诉我...

【问题讨论】:

    标签: iphone xcode


    【解决方案1】:

    可以先画渐变,拿到图片,然后用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];
    

    【讨论】:

    • 哇,谢谢,太好了!但我很抱歉......我想改变“UIScopeBarButton”。然后我写了 [searchBar setScopeBarButtonBackgroundImage:image forState:normal];但效果不好。 ...我想投票给你的答案,但我没有足够的声誉。
    【解决方案2】:

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

    [searchBar setScopeBarBackgroundImage:[UIImage imageNamed:@"bg.jpg"]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      相关资源
      最近更新 更多