我正在尝试制作五种颜色中的UILabel
- (void)viewDidLoad {
[super viewDidLoad];
NSString *randomColor = [colorArray objectAtIndex: arc4random() % [colorArray count]];
colorArray = [[NSArray alloc] init];
[UIColor redColor], [UIColor blueColor], [UIColor greenColor], [UIColor yellowColor];
colorLabel.textColor = randomColor;
}
如何将数组中的对象设置为标签textColor的UIColor
?对不起,如果已经回答了这个问题,我就无法找出正确的方法来对其进行查找。
答案 0 :(得分:1)
试试这个......
#define kNumColors 4
- (UIColor *) randomColor
{
NSInteger colorIndex = arc4random() % kNumColors;
UIColor *color;
switch (colorIndex) {
case 0:
color = [UIColor blueColor];
break;
case 1:
color = [UIColor redColor];
break;
case 2:
color = [UIColor yellowColor];
break;
case 3:
color = [UIColor greenColor];
break;
}
return color;
}
指定随机颜色......
colorLabel.textColor = [self randomColor];