-(Void) viewDidLoad
{
[Super viewDidLoad];
// Label initialization color
[_ Label setBackgroundColor: [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 100];
// View background color change
// 1/20. 0. The error may occur once if the execution is performed 20 times in one second.
NSTimer * timer = [NSTimerscheduledTimerWithTimeInterval: 1/20. 0 target: self selector: @ selector (testChangeViewBackColor) userInfo: nilrepeats: YES];
// Start
[Timer fire];
// The label background color changes.
NSTimer * timer2 = [NSTimerscheduledTimerWithTimeInterval: 1/50. 0 target: self selector: @ selector (testChangeLableBackColor) userInfo: nilrepeats: YES];
[Timer2 fire];
}
-(Void) testChangeLableBackColor
{
// Obtain the background color
UIColor * color = [self-> _ labelbackgroundColor];
Const CGFloat * components = CGColorGetComponents (color. CGColor );
// Obtain the RGB color
CGFloat red = components [0];
CGFloat green = components [1];
CGFloat blue = components [2];
// This is what I debugged. Originally, I wanted to make it <255 discover this effect. If anyone knows what it means, share it with me.
// I guess this is to make 1. When it is not black 2. I don't know
If (red! = 1)
{
// Set the label. Each time rgb + 1 is passed in, the label cannot contain an integer.
// Alpha: 0.5 sets translucent
[Self-> _ labelsetBackgroundColor: [UIColorcolorWithRed: red + 1.0/255.0 green: green + 1.0/255.0 blue: blue + 1.0/255.0 alpha: 0.5];
}
Else
{
// A time factor must be set before the random RGB color is specified. Otherwise, each time is the same.
Time (NULL );
CGFloat red = (CGFloat) random ()/(CGFloat) RAND_MAX;
CGFloat green = (CGFloat) random ()/(CGFloat) RAND_MAX;
CGFloat blue = (CGFloat) random ()/(CGFloat) RAND_MAX;
[Self-> _ labelsetBackgroundColor: [UIColorcolorWithRed: redgreen: greenblue: bluealpha: 0.5];
}
}
-(Void) testChangeViewBackColor
{
Static BOOL seeded = NO;
If (! Seeded)
{
Seeded = YES;
Time (NULL );
}
CGFloat red = (CGFloat) random ()/(CGFloat) RAND_MAX;
CGFloat green = (CGFloat) random ()/(CGFloat) RAND_MAX;
CGFloat blue = (CGFloat) random ()/(CGFloat) RAND_MAX;
[_ Myview setBackgroundColor: [UIColor colorWithRed: red green: green blue: blue alpha: 1];
}