我添加了一个自定义视图,并想绘制一个内部较小的圆圈、外部较大的圆圈和垂直线。drawRect:
我班上的方法是这样的。
- (void) drawRect:(CGRect)rect{
CGContextRef myContext = UIGraphicsGetCurrentContext();
float height = rect.size.height;
float width = rect.size.width;
CGContextTranslateCTM(myContext, 0.0, height);
CGContextScaleCTM(myContext, 1.0, -1.0);
CGPoint middle = CGPointMake(width/2, height/2);
UIBezierPath *innerCirclePath = [UIBezierPath bezierPathWithArcCenter:middle radius:25 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
[innerCirclePath setLineWidth:2];
[[UIColor redColor] setStroke];
[innerCirclePath stroke];
UIBezierPath *outerCirclePath = [UIBezierPath bezierPathWithArcCenter:middle radius:120 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:NO];
[outerCirclePath setLineWidth:2];
[[UIColor greenColor] setStroke];
[outerCirclePath stroke];
UIBezierPath *xAxis = [UIBezierPath bezierPath];
[xAxis moveToPoint:CGPointMake(width, height/2 - 150)];
[xAxis addLineToPoint:CGPointMake(width, height/2 + 150)];
[xAxis closePath];
[[UIColor grayColor] setStroke];
[xAxis setLineWidth:2];
[xAxis stroke];
}
现在我确实得到了外圈和内圈,但没有我想要的垂直线。为什么不被绘制?