直接上代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"背景颜色的随机显示"; CGFloat red = (CGFloat)arc4random() / 0x100000000; CGFloat green = (CGFloat)arc4random() / 0x100000000; CGFloat blue = (CGFloat)arc4random() / 0x100000000; self.view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0f]; }