UIColor:
*Creating a UIColor
There are many ways you can create a UIColor:
Swift
let redColor = UIColor.redColor()
let blueColor: UIColor = .blueColor()
// In Swift 3, the "Color()" suffix is removed:
let redColor = UIColor.red
let blueColor: UIColor = .blue
If the compiler already knows that the variable is an instance of UIColor you can skip the type all together:
let view = UIView()
view.backgroundColor = .yellowColor()
let grayscaleColor = UIColor(white: 0.5, alpha: 1.0)
let hsbColor = UIColor(
hue: 0.4,
saturation: 0.3,
brightness: 0.7,
alpha: 1.0
)
let rgbColor = UIColor(
red: 30.0 / 255,
green: 70.0 / 255,
blue: 200.0 / 255,
alpha: 1.0
)
let patternColor = UIColor(patternImage: UIImage(named: "myImage")!)
Objective-C
UIColor *redColor = [UIColor redColor];
UIColor *grayscaleColor = [UIColor colorWithWhite: 0.5 alpha: 1.0];
UIColor *hsbColor = [UIColor
colorWithHue: 0.4
saturation: 0.3
brightness: 0.7
alpha: 1.0
];
UIColor *rgbColor = [UIColor
colorWithRed: 30.0 / 255.0
green: 70.0 / 255.0
blue: 200.0 / 255.0
alpha: 1.0
];
UIColor *pattenColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]];