ios - 为什么我的 UIColor 无法正确创建?

标签 ios colors uibutton rgb uicolor

<分区>

我需要帮助!我对此很陌生,我正在尝试制作一个带有填充颜色的 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];

然后按钮所在的屏幕上什么也没有,只有白色。我不明白为什么会遇到这个问题,但非常感谢您的帮助!

最佳答案

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

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

如果它有效或您需要更多帮助,请告诉我。

关于ios - 为什么我的 UIColor 无法正确创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514115/

上一篇:iphone - 如何从第二个 View Controller 以编程方式创建选项卡栏

下一篇:ios - 如何将 iOS 上的 "may not respond to XXX"警告转换为错误?

相关文章:

ios - 这是什么 iOS Controller ?

ios - 制作一个 UITableView "sticky to the bottom"

algorithm - 使用 "hue"混合模式混合两种非不透明颜色

ios - UIButton 此类与键的键值代码不兼容

ios - iOS 中的自定义按钮和状态

ios - 如何在 iTunes Connect 中查看崩溃原因?

ios - UICollectionview 委托(delegate)和数据源未开始调用

excel - 更改散点图vba excel中特定点的颜色

colors - Highcharts 面积图,在 X 轴上方/下方使用 2 种填充颜色

ios - UIButton执行三个 Action ?