【问题标题】:When I change the color of UITabBar it only shows up in gray当我更改 UITabBar 的颜色时,它只显示为灰色
【发布时间】:2012-12-03 06:42:59
【问题描述】:

我在选项卡式应用的各种视图控制器的“viewDidLoad”中使用以下代码。

    UIColor *tabBarColor = [UIColor colorWithRed:85.1 green:57.6 blue:71.4 alpha:.5];
    [[UITabBar appearance] setTintColor:tabBarColor];

但是我得到的应该是粉红色的图像是这样的:

我可以通过更改 alpha 来使其更亮或更暗,但从不着色——只有黑色/白色/灰色。

有什么想法可以解决这个问题吗?

【问题讨论】:

标签: objective-c ios uitabbar


【解决方案1】:

在 .m 的头文件下写下这一行 #define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1] 现在你要设置颜色的地方把这个代码设置为粉红色 [[UITabBar appearance] setTintColor:RGB(255, 192, 203)]; 就是这样

【讨论】:

    【解决方案2】:

    试试这个:

       if ([tabBarController.tabBar respondsToSelector:@selector(setTintColor:)]) 
        {
            [tabBarController.tabBar setTintColor: tabBarColor];
        }
    

    【讨论】:

      【解决方案3】:

      颜色必须在数字后带有小数点:215.0/255。因为它是浮动的。
      如果您想在 32 位和 64 位系统上精确使用浮点数和双精度数,您还应该在数字后添加 f215.0f/255。编译器会知道它是 32 位的。 现在你的问题是你没有写分界线:N_OF_COLORS / TOTAL_COLORS

      【讨论】:

        【解决方案4】:

        UIColor *tabBarColor = [UIColor colorWithRed:85.1 green:57.6 blue:71.4 alpha:.5]

        颜色必须在数字后带有小数点:215.0/255。因为它是浮动的。

        试试这个:

        UIColor *tabBarColor = [UIColor colorWithRed:(87/255.0) green:(153/255.0) blue:(165/255.0) alpha:1];
        
        
        [[UITabBar appearance] setTintColor:tabBarColor];
        

        【讨论】:

          猜你喜欢
          • 2021-07-30
          • 2015-06-03
          • 2021-08-08
          • 2015-02-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-09-01
          相关资源
          最近更新 更多