iPhone应用程序-为什么我的背景圆圈看起来像黑色正方形?
我的iPhone应用程序自定义UIView类中的drawRect方法有什么问题?它应该画一个彩色的圆圈,但是它画了一个适当宽度和高度的黑色正方形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
- (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));
}