【问题标题】:UITabBar selectedImageTintColor with RGB doesn't work带有 RGB 的 UITabBar selectedImageTintColor 不起作用
【发布时间】:2014-07-13 13:58:16
【问题描述】:

当我以这种方式设置 UITabBar 的 selectedImageTintColor 时,代码有效:

[[UITabBar appearance] setSelectedImageTintColor: [UIColor orangeColor]];

但是当我用 RGB 设置时,像这样

[[UITabBar appearance] setSelectedImageTintColor: [UIColor colorWithRed:255/255 green:162/255 blue:0/250 alpha:1]];

哪个是浅一点的橙色,

UITabBar的selectedImageTintColor变成红色

【问题讨论】:

    标签: ios objective-c uitableview uicolor


    【解决方案1】:

    在每个/255的末尾添加.0f

    [[UITabBar appearance] setSelectedImageTintColor: 
        [UIColor colorWithRed:255/255.0f 
                        green:162/255.0f 
                         blue:0/250.0f 
                        alpha:1]]; 
    

    出现问题是因为 162/255 被识别为对 int 值的操作,因此当它自动舍入并且您收到 0 所以您最终的颜色是 R:255 G:0 B:0 这正是您得到的。添加.0f 告诉编译器您要处理浮点数,这样精度就不会丢失,并且您可以通过分数获得值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 2021-09-05
      相关资源
      最近更新 更多