gpt4 book ai didi

ios CGContextRef 填充颜色

转载 作者:行者123 更新时间:2023-11-29 11:32:17 25 4
gpt4 key购买 nike

我想画一个圆弧并填充它。第一张图是这样的。我想得到第二张图的效果

The current

I want

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// 必须清空背景色,不然绘制出来的区域之外有黑色背景
[self setBackgroundColor:[UIColor clearColor]];
[self setUserInteractionEnabled:NO];
}
return self;
}

- (void)drawRect:(CGRect)rect {
float x = rect.origin.x;
float y = rect.origin.y;
float w = rect.size.width;
float h = rect.size.height;
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *fullColor = [UIColor whiteColor];
CGContextSetFillColorWithColor(context, fullColor.CGColor);
CGContextSetRGBStrokeColor(context,1,1,1,1);
CGContextMoveToPoint(context,0,h - 22);//圆弧的起始点
CGContextAddQuadCurveToPoint(context, w / 2, h, w, h - 22);
CGContextMoveToPoint(context,0,h - 22);//圆弧的起始点
CGContextAddLineToPoint(context, 0, h);
CGContextAddLineToPoint(context, w, h);
CGContextAddLineToPoint(context, w, h - 22);

CGContextStrokePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
}

最佳答案

- (void)drawRect:(CGRect)rect {
float x = rect.origin.x;
float y = rect.origin.y;
float w = rect.size.width;
float h = rect.size.height;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, CGRectMake(0, h - 22, kScreenWidth , 22));
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
// This method
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextMoveToPoint(context,0,h - 22);
CGContextAddQuadCurveToPoint(context, w / 2, h + 14, w, h - 22);
CGContextDrawPath(context, kCGPathFill);
// This method
CGContextSetBlendMode(context, kCGBlendModeNormal);
}

我找到了解决方案。

关于ios CGContextRef 填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52292526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com