It is probably best to use the backgroundColor property of your UIImageView. You can do it as follows:
self.imageView.backgroundColor = UIColor.redColor()
The following predefined colors are available:
blackColor darkGrayColor lightGrayColor whiteColor grayColor redColor greenColor blueColor cyanColor yellowColor magentaColor orangeColor purpleColor brownColor clearColor
If you want to programmatically create a UIImage with a given color, you can do it like this:
var rect = CGRectMake(0, 0, size.width, size.height) UIGraphicsBeginImageContextWithOptions(size, false, 0) color.setFill() UIRectFill(rect) var image: UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()
Where var 'image' is your color UIImage.
source share