【问题标题】:Why will my UIColor not create properly? [closed]为什么我的 UIColor 不能正确创建? [关闭]
【发布时间】:2013-05-07 00:26:34
【问题描述】:

我需要帮助!我对此很陌生,我正在尝试制作一个带有填充颜色的 UIButton,但是每次我尝试创建我的 UIColor 来填充它时都不起作用。

当我使用时:

UIColor *orangeButtonColor = [UIColor blackColor];
UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(6, 9, 64, 64);
[firstButton setTitle:@"Select" forState:UIControlStateNormal];
firstButton.backgroundColor = orangeButtonColor;
[self.view addSubview:firstButton];

它在我的屏幕上提供了一个黑色按钮,但我想要一个使用 RGB 颜色的自定义彩色按钮(实际上 CMYK 是我的偏好,但我也无法做到这一点)。所以我把我的代码改成这样:

UIColor *orangeButtonColor = [UIColor colorWithRed:246 green:180 blue:119 alpha:1];
UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
firstButton.frame = CGRectMake(6, 9, 64, 64);
[firstButton setTitle:@"Select" forState:UIControlStateNormal];
firstButton.backgroundColor = orangeButtonColor;
[self.view addSubview:firstButton];

然后屏幕上没有按钮所在的位置,只有白色。我不明白为什么我会遇到这个问题,但我们将不胜感激!

【问题讨论】:

标签: ios colors uibutton rgb uicolor


【解决方案1】:

尝试将颜色除以 255。尝试以下操作

  UIColor *orangeButtonColor = [UIColor colorWithRed:246/255.0 green:180/255.0 blue:119/255.0 alpha:1];

让我知道它是否有效或者您需要更多帮助。

【讨论】:

    猜你喜欢
    • 2011-07-26
    • 2021-03-13
    • 1970-01-01
    • 2016-12-01
    • 2021-02-05
    • 2013-01-31
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    相关资源
    最近更新 更多