【问题标题】:UIToolBar tintColor not working for iOS 7UIToolBar tintColor 不适用于 iOS 7
【发布时间】:2014-01-25 05:14:24
【问题描述】:

我在我的应用程序中创建了一个蓝色的UIToolBar,当我将它构建为 iOS 6 时它显示为蓝色,但现在我已经将构建更新到 iOS 7 它变成了白色?

这是我的代码。

getProjectListToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 20.0, screenHeight+20, 44)];
getProjectListToolBar.tintColor = [UIColor colorWithRed:85.0/255.0 green:130.0/255.0 blue:186.0/255.0 alpha:1.0];

getProjectListToolBar.translucent = NO;
getProjectListToolBar.layer.borderWidth = 0.0;
getProjectListToolBar.backgroundColor = [UIColor clearColor];
getProjectListToolBar.layer.borderWidth = 0.5;
getProjectListToolBar.layer.borderColor = [UIColor darkGrayColor].CGColor;
[self.view insertSubview:getProjectListToolBar aboveSubview:self.view];

我怎样才能让它再次变蓝?

【问题讨论】:

    标签: ios iphone objective-c uitoolbar


    【解决方案1】:

    你只需要设置

    getProjectListToolBar.translucent = NO;
    

    在 iOS 7 中 UITabBarUINavigationBar 具有 translucent 属性,您需要设置 translucent = NO ,仅供参考。

    已编辑

    [getProjectListToolBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:130.0/255.0 blue:186.0/255.0 alpha:1.0]];
    

    因为在 iOS 7 中你需要设置 barTintColor 而不是 tintColor from this documentation.

    我在我的演示项目中尝试了您的代码,它对我有用。

    【讨论】:

    • 我已经用你给我看的代码更新了我的问题,对吗?因为它仍然没有更改为正确的颜色...我稍后继续使用 [getProjectListToolBar setItems:buttonsArray animated:YES]; 设置一些项目,这会导致背景任何颜色问题吗?跨度>
    【解决方案2】:

    在ios7中有2个属性:

    1. tintColor:将设置工具栏项的颜色
    2. barTintColor : 设置工具栏颜色

    使用 barTintColor。

    【讨论】:

      【解决方案3】:

      请从您的代码中删除:

      getProjectListToolBar.tintColor = [UIColor colorWithRed:85.0/255.0  green:130.0/255.0 blue:186.0/255.0 alpha:1.0];
      

      并添加一行

      [getProjectListToolBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:130.0/255.0 blue:186.0/255.0 alpha:1.0]];
      

      并检查您的“getProjectListToolBar”框架坐标

      【讨论】:

        猜你喜欢
        • 2021-11-15
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2013-09-12
        • 1970-01-01
        • 2013-10-30
        • 1970-01-01
        • 2013-11-03
        相关资源
        最近更新 更多