var color1:CGFloat = CGFloat(CGFloat(random())/CGFloat(RAND_MAX))
var color2:CGFloat = CGFloat(CGFloat(random())/CGFloat(RAND_MAX))
var color3:CGFloat = CGFloat(CGFloat(random())/CGFloat(RAND_MAX))
self.view.backgroundColor= UIColor(red: color,green: color1,blue: color2,alpha: 1);
原文链接:https://www.f2er.com/swift/326818.html