尝试使用自定义UIColor实例(ObjC)

时间:2016-11-05 10:22:06

标签: objective-c xcode uicolor

我的代码出了什么问题?

- (IBAction)randomColour:(id)sender {

    CGFloat hue = ( arc4random() % 256 / 256.0 );  //  0.0 to 1.0

    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from white

    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;  //  0.5 to 1.0, away from black

    UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];

    self.Label.textColor = [UIColor color];
    self.Label2.textColor = [UIColor color];
}

我已尝试初始化颜色变量和UIColor无处不在,但我一直低于错误:

  

选择器'color'没有已知的类方法

即使它就在那里!

1 个答案:

答案 0 :(得分:1)

self.Label.textColor = color; self.Label2.textColor = color;