Swift 2.2: set background image with background color
UIGraphicsBeginImageContextWithOptions(stationNameLabel.frame.size, false, 0.0) let context = UIGraphicsGetCurrentContext(); let components = CGColorGetComponents(color.CGColor) CGContextSetRGBFillColor(context, components[0], components[1], components[2], 0.4); CGContextFillRect(context, CGRectMake(0.0, 0.0, stationNameLabel.frame.size.width, stationNameLabel.frame.size.height)); targetImage.drawInRect(CGRectMake(0.0, 0.0, stationNameLabel.frame.size.width, stationNameLabel.frame.size.height)) let resultImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() label.backgroundColor = UIColor(patternImage: resultImage)
Bill Chan Apr 12 '16 at 14:29 2016-04-12 14:29
source share