【发布时间】: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];
然后屏幕上没有按钮所在的位置,只有白色。我不明白为什么我会遇到这个问题,但我们将不胜感激!
【问题讨论】:
-
希望您仔细阅读以下文档:developer.apple.com/library/ios/documentation/UIKit/Reference/…:这是否告诉您为什么您的颜色总是白色? (提示:查看 + colorWithRed:green:blue:alpha 部分:)
标签: ios colors uibutton rgb uicolor