ios – 透明背景UIView drawRect圆

我用一个白色笔画和一个由属性指定的颜色绘制一个圆圈,使用这段代码:
- (void)drawRect:(CGRect)rect {

    CGContextRef contextRef = UIGraphicsGetCurrentContext();

    CGContextClearRect(contextRef,rect);

    // Set the border width
    CGContextSetLineWidth(contextRef,1.5);

    // Set the circle fill color to GREEN
    CGFloat red,green,blue,alpha;
    BOOL didConvert = [_routeColor getRed:&red green:&green blue:&blue alpha:&alpha];

    CGContextSetRGBFillColor(contextRef,red,1.0);

    // Set the cicle border color to BLUE
    CGContextSetRGBStrokeColor(contextRef,255.0,1.0);

    // Fill the circle with the fill color
    CGContextFillEllipseInRect(contextRef,rect);

    // Draw the circle border
    CGContextStrokeEllipseInRect(contextRef,rect);
}

我得到的图像看起来像这样:

如何清除黑色?

解决方法

将视图的backgroundColor设置为[UIColor clearColor].

注意,只有在创建视图时,才需要设置背景颜色一次.

以上是来客网为你收集整理的ios – 透明背景UIView drawRect圆全部内容,希望文章能够帮你解决ios – 透明背景UIView drawRect圆所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。