创建一个UIImage的Category添加一下方法: 123456789101112+ (instancetype)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = [UIImage new]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image;}