background color to image

self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))

UIView:

let banner = UIView(frame: CGRectMake(x, y, width, height))

UIGraphicsBeginImageContext(banner.frame.size)
UIImage(named: "banner_promo")?.drawInRect(banner.bounds)
var image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
banner.backgroundColor = UIColor(patternImage: image)

Tags: