+ (UIImage *)pureColorImageWithColor:(UIColor *)color { CGSize imageSize = CGSizeMake(1.0f, 1.0f); UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f);
CGContextRef theContext = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(theContext, color.CGColor); CGContextFillRect(theContext, CGRectMake(0.0f, 0.0f, imageSize.width, imageSize.height));
CGImageRef theCGImage = CGBitmapContextCreateImage(theContext); UIImage *theImage; if ([[UIImage class] respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) { theImage = [UIImage imageWithCGImage:theCGImage scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]; } else { theImage = [UIImage imageWithCGImage:theCGImage]; } CGImageRelease(theCGImage);
return theImage; }
+ (UIImage *)pureColorImageWithSize:(CGSize)size color:(UIColor *)color cornRadius:(CGFloat)radius { UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef cxt = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(cxt, color.CGColor); CGContextSetStrokeColorWithColor(cxt, color.CGColor);
CGContextMoveToPoint(cxt, size.width, size.height-radius); CGContextAddArcToPoint(cxt, size.width, size.height, size.width-radius, size.height, radius); CGContextAddArcToPoint(cxt, 0, size.height, 0, size.height-radius, radius); CGContextAddArcToPoint(cxt, 0, 0, radius, 0, radius); CGContextAddArcToPoint(cxt, size.width, 0, size.width, radius, radius); CGContextClosePath(cxt); CGContextDrawPath(cxt, kCGPathFillStroke); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
|