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].

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...