当我改变UITabBar的颜色时,它只显示为灰色

时间:2012-12-03 06:42:59

标签: objective-c ios uitabbar

我在我的标签应用的各种视图控制器的'viewDidLoad'中使用以下代码。

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

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

enter image description here

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

关于如何解决这个问题的任何想法?

4 个答案:

答案 0 :(得分:5)

在.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)];全部

答案 1 :(得分:1)

试试这个:

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

答案 2 :(得分:1)

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

答案 3 :(得分:0)

UIColor * tabBarColor = [UIColor colorWithRed:85.1绿色:57.6蓝色: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];