生成随机颜色的IOS目标c?

时间:2016-08-19 09:11:09

标签: ios objective-c

生成随机颜色

float red   = (float)(arc4random() % 255)/255.0;  
float blue  = (float)(arc4random() % 255)/255.0;  
float green = (float)(arc4random() % 255)/255.0;  
view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; 

或使用此

每次都改变视图背景是唯一的颜色

 for(int i=0;i<100;i++) {  

  float red   = (float)(arc4random() % 255)/255.0;  
    float blue  = (float)(arc4random() % 255)/255.0;  
    float green = (float)(arc4random() % 255)/255.0;  
    view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; 
}

1 个答案:

答案 0 :(得分:0)

它将为您生成随机颜色:

onStop()