1

在我UITableViewController的单元格中,我想显示一个带有数字的圆圈。我正在使用UIBezierPath'sbezierPathWithOvalInRect:来绘制圆圈。

不幸的是,虽然我可以将fill颜色设置为,但传递给clearColor的未使用部分是黑色。CGRectbezierPathWithOvalInRect:

如何摆脱创建的黑色区域?

部分截图供参考:(
截屏
我最终希望得到圈内的那个数字)

代码:

LTTTableViewCell:

- (void)awakeFromNib {
    [super awakeFromNib];

    // Create a square view using the height of the cell
    CGRect positionFrame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height);
    LTTDrawBallView *drawBallView = [[LTTDrawBallView alloc] initWithFrame:positionFrame];
    [self.contentView addSubview:drawBallView];
}

LTTDrawBallView:

- (void)drawRect:(CGRect)rect
{
    // Create a new rect with some padding  
    // + create a circle from this new rect:
    CGRect box = CGRectInset(self.bounds, self.bounds.size.width * 0.1f, self.bounds.size.height * 0.1f);
    UIBezierPath *ballBezierPath = [UIBezierPath bezierPathWithOvalInRect:box];
    [[UIColor whiteColor] setStroke];
    [[UIColor greenColor] setFill]; // Green here to show the black area
    [ballBezierPath stroke];
    [ballBezierPath fill];
    [self setBackgroundColor:[UIColor clearColor]]; // Happens with and without this line
}
4

1 回答 1

4

在 LTTDrawBallView 的 init 方法中,包含以下代码:

self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
于 2013-08-07T23:48:09.597 回答