Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone应用程序-为什么我的背景圆圈看起来像黑色正方形?_Iphone_Ios_Ipad_Uiview_Cgcontext - Fatal编程技术网

iPhone应用程序-为什么我的背景圆圈看起来像黑色正方形?

iPhone应用程序-为什么我的背景圆圈看起来像黑色正方形?,iphone,ios,ipad,uiview,cgcontext,Iphone,Ios,Ipad,Uiview,Cgcontext,我的iPhone应用程序自定义UIView类中的drawRect方法有什么问题?它应该画一个彩色的圆圈,但是它画了一个适当宽度和高度的黑色正方形 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); UIColor *c = [UIColor redColor]; const

我的iPhone应用程序自定义UIView类中的drawRect方法有什么问题?它应该画一个彩色的圆圈,但是它画了一个适当宽度和高度的黑色正方形

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    UIColor *c = [UIColor redColor];
    const CGFloat *components = CGColorGetComponents([c CGColor]);
    CGFloat red = components[0];
    CGFloat green = components[1];
    CGFloat blue = components[2];
    CGFloat al = components[3];     
    CGContextSetRGBFillColor(context, red, green, blue, al);
    CGContextFillEllipseInRect(context, CGRectMake(x, y, width, width));
}
试试这个:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddEllipseInRect(ctx, CGRectMake(x, y, width, width));
    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor redColor] CGColor]));
    CGContextFillPath(ctx);
}
希望这一切顺利

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    CGContextSetFillColorWithColor(context , [UIColor redColor].CGColor;
    CGContextFillEllipseInRect(context, CGRectMake(x, y, width, width));
}