func image(with color: UIColor) -> UIImage { let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() context?.setFillColor(color.cgColor) context?.fill(rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! }

- UIImage imageWithColorUIColor color CGRect rect = CGRectMake00f00f 10f10f; UIGraphicsBeginImageContextrectsize; CGContextRef context =UIGraphicsGetCurrentContext; CGContextSetFillColorW

原文地址: https://www.cveoy.top/t/topic/iNJ6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录