iphone - SearchBar TintColor 未应用正确

标签 iphone objective-c ios colors uisearchbar

我的 SearchBar 的 TintColor 有问题。我在导航栏和搜索栏中使用相同的 RGB 颜色。正如您在下面看到的,颜色不一样。

enter image description here

这是我用来设置导航栏 TintColor 的代码:

    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1];

这就是我用来设置 searchBar 的 TintColor 的。

    self.mySearchBar.tintColor = [UIColor colorWithRed:34/255.0f green:113/255.0f blue:179/255.0f alpha:1];

因此,如您所见,这两行几乎相同。关于如何获得相同颜色的任何想法?

非常感谢任何建议!

编辑: 我使用 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];

但这种方法的问题是它不会被准确着色。

更新: imageWithColorUIImage 上的类别。

+ (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;
}

关于iphone - SearchBar TintColor 未应用正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854532/

相关文章:

ios - iOS 6 状态保存和恢复的自动化测试

iphone - 在 iOS 上使用 Quartz 获取当前页面的 PDF 超链接

iphone - 应用程序进入后台时的内存占用

iphone - iPad:如何将iPhone应用程序转换为iPad兼容?

objective-c - 如何使 Mac 上的对象消失?

ios - objective-C : Table cell just returns last information of matching data

ios - 使用 presentModalViewController 但使用 modeUIViewAnimationTransitionCurlUp

iPhone4 960x640 - 对应用程序有影响吗?

objective-c - Zbar SDK 在 iOS6 中不工作

iphone - 代码无法在 iPhone 上运行,但可以在模拟器上运行