Merhabalar bu yazımda iOS uygulamalarınızda işinize yarayabilecek, Belirlediniz rengi UIImage nesnesine nasıl dönüştürebileceğinizi göstereceğim.
Bu işlem ile sadece tek bir renk arka fona sahip UIImage nesnesi elde edip, bunu uygulamanızda kullanabilirsiniz.
Bu işlem için CoreGraphics yardımcı sınıflarından yararlanacağız. İşlem oldukça basit.
extension UIColor { static func image(_ color: UIColor) -> UIImage { let rect = CGRect(x: 0, y: 0, width: 1, height: 1) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext()! context.setFillColor(color.cgColor) context.fill(rect) let img = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return img! } }
imgView.image = UIColor.image(.red)
İlk Yorumu Siz Yapın