CGSize imageSize =CGSizeMake(50,50);
UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreenmainScreen].scale);
[RGBA(206,58, 216, 1) set];
UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
UIImage *pressedColorImg =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
或者:
You will want to clip the context to an image mask and then fill with a solid color:
- (void)drawRect:(CGRect)rect
{
CGRect bounds = [self bounds];
[[UIColor blackColor] set];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, bounds, [myImage CGImage]);
CGContextFillRect(context, bounds);
}
Note: myImage should
be an instance variable that contains an UIImage.
I'm not sure whether it takes the mask from the alpha channel or the intensity so try both.
本文介绍了如何使用UIKit框架中的UIGraphicsBeginImageContextWithOptions等方法来创建一个特定尺寸且具有固定颜色的图片。此外,还提供了另一种方法,通过利用当前绘图上下文并结合UIImage进行裁剪来填充指定颜色。
1622

被折叠的 条评论
为什么被折叠?



