9

我有一个自定义表格视图单元格,旨在像 iPhone 的 Mail.app 一样绘制一个圆圈:

不烂的圈子

相反,它是这样绘制的:

很烂的圈子

这是我的代码:

CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *grayColor = [UIColor grayColor];

[grayColor set];

CGContextStrokeEllipseInRect(context, CGRectMake(9, 10, 23, 23));

我怎样才能让它不烂?:)

编辑:忽略我省略了绘制白色背景颜色的代码这一事实。

糟透了怎么办?它看起来不接近,如果不完全像,邮件中的圆圈。

4

2 回答 2

18

我能够通过将其更改为UIColorApple 使用的相同颜色来解决此问题#E5E5E5

[UIColor colorWithRed: 0.8980392157 green: 0.8980392157 blue: 0.8980392157 alpha: 1.0]

并将线宽从默认更改1.02.0

CGContextSetLineWidth(context, 2.0);

调整大小也是必要的:

CGContextStrokeEllipseInRect(context, CGRectMake(10, 11, 21, 21));

最终代码如下所示:

CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *grayColor = [UIColor colorWithRed: 0.8980392157 green: 0.8980392157 blue: 0.8980392157 alpha: 1.0];

[grayColor set];

CGContextSetLineWidth(context, 2.0);
CGContextStrokeEllipseInRect(context, CGRectMake(10, 11, 21, 21));

和这样的输出:

不烂的圈子

于 2010-11-30T16:32:10.427 回答
5

尝试将其 alpha 设置为 0.5 并使边框变粗,例如,像这样:

CGContextSetAlpha(context, 0.5);
于 2010-11-30T15:50:45.730 回答