我有一个自定义表格视图单元格,用于绘制像iPhone的Mail.app那样的圆圈:
相反,它是这样绘制的:
这是我的代码:
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *grayColor = [UIColor grayColor];
[grayColor set];
CGContextStrokeEllipseInRect(context, CGRectMake(9, 10, 23, 23));
我怎样才能让它不吸?:)
编辑:忽略我省略了绘制白色背景颜色的代码的事实。
它糟透了?它看起来并不像Mail中的圆圈那么接近(如果不完全一样)。
答案 0 :(得分:18)
我能够通过将UIColor
更改为Apple使用的相同颜色#E5E5E5
来解决此问题:
[UIColor colorWithRed: 0.8980392157 green: 0.8980392157 blue: 0.8980392157 alpha: 1.0]
将线宽从默认1.0
更改为2.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));
这样的输出:
答案 1 :(得分:5)
尝试将其alpha设置为0.5并使边框更粗,例如,如下所示:
CGContextSetAlpha(context, 0.5);