Hello, this is @ Zhalen. I'm really going to die from lack of money.
In this article, I will introduce an extension that outputs colors randomly like this.
Extension
This is the extension.
//MARK:-Random color
extension UIColor {
static func random() -> UIColor {
let red: CGFloat = CGFloat.random(in: 0...1)
let green: CGFloat = CGFloat.random(in: 0...1)
let blue: CGFloat = CGFloat.random(in: 0...1)
return UIColor.init(red: red, green: green, blue: blue, alpha: 1)
}
}
Please describe this ↑ somewhere in the file
UIColor.random()
If you write, a random color will appear.
here,
CGFloat.random(in: 0...1)
Is a `that randomly returns a CGFloat type from`
0 to 1, so this extension is realized by generating a random rgb value with a random initial value of `` `UIColor```. I am.
Just the other day, we released a questionnaire-specific SNS " Vote. "!
This app is useful not only when you are at a loss or worried about your choice, but also in practical aspects such as corporate A/B testing and test marketing! The design is very sophisticated, and anyone can easily take questionnaires and votes.