iOS UIColor Color with Alpha component

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

You can set the opacity to a certain UIColor without creating a new one using the init(red:_,green:_,blue:_,alpha:_) initializer.

Swift

let colorWithAlpha = UIColor.redColor().colorWithAlphaComponent(0.1)

Swift 3

//In Swift Latest Version
_ colorWithAlpha = UIColor.red.withAlphaComponent(0.1)

Objective-C

UIColor * colorWithAlpha = [[UIColor redColor] colorWithAlphaComponent:0.1];


Got any iOS Question?