Mar*_*rco 3 iphone colors objective-c uisearchbar ios
我的SearchBar的TintColor有问题.我在导航栏和搜索栏上使用相同的RGB颜色.如下所示,颜色不一样.

这是我用来设置导航栏的TintColor的代码:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1];
Run Code Online (Sandbox Code Playgroud)
这就是我用来设置searchBar的TintColor.
self.mySearchBar.tintColor = [UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1];
Run Code Online (Sandbox Code Playgroud)
所以,正如你所看到的那样,这两行几乎是一样的.关于如何获得相同颜色的任何想法?
任何建议非常感谢!
编辑:我使用XCode 4.3.3为iOS 4.0开发,并在iOS 5的设备上测试
我有类似的问题,这就是我最终做的事情,
[[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1]]];
[[UIToolbar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1]] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
但这种方法的问题在于它不会完全着色.
更新:
imageWithColor是类别UIImage.
+ (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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1132 次 |
| 最近记录: |