- UIColorからUIImageを生成
extension UIImage {
static func image(filled color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
defer {
UIGraphicsEndImageContext()
}
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContext(rect.size)
let contextRef = UIGraphicsGetCurrentContext()
contextRef!.setFillColor(color.cgColor)
contextRef!.fill(rect)
return UIGraphicsGetImageFromCurrentImageContext()!
}
}