gpt4 book ai didi

iOS 绘制填充圆

转载 作者:IT王子 更新时间:2023-10-29 07:44:04 26 4
gpt4 key购买 nike

我不是这里的图形程序员,所以我正在努力解决这个问题。我正在尝试绘制 9 个实心圆圈,每个圆圈的颜色不同,每个圆圈都有白色边框。 UIView 的框架是 CGRectMake (0,0,60,60)。见附图。

问题是我在每一边的边界上都出现了“扁平点”。以下是我的代码(来自 UIView 子类):

- (void)drawRect:(CGRect)rect
{
CGRect borderRect = CGRectMake(0.0, 0.0, 60.0, 60.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(context, colorRed, colorGreen, colorBlue, 1.0);
CGContextSetLineWidth(context, 2.0);
CGContextFillEllipseInRect (context, borderRect);
CGContextStrokeEllipseInRect(context, borderRect);
CGContextFillPath(context);
}

如果我在 drawRect 中更改为 CGRectMake(0,0,56,56),我只会在顶部和左侧得到平点,而底部和右侧看起来很好。

谁能建议我如何解决这个问题?在我看来,边框被 UIView 剪掉了,但对此了解不多,我真的不知道如何修复它。

提前感谢图形专家的任何建议。

enter image description here

最佳答案

我喜欢@AaronGolden 的回答,只是想补充:

CGRect borderRect = CGRectInset(rect, 2, 2);

或者,更好的是:

CGFloat lineWidth = 2;
CGRect borderRect = CGRectInset(rect, lineWidth * 0.5, lineWidth * 0.5);

关于iOS 绘制填充圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17038017/

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