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