Reputation:
i added a custom view and want to draw an inner smaller circle, outer bigger circle and and perpendicular line. the drawRect:
method in my class looks like this.
- (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];
}
Now I do get the circles, both outer and inner but there is no perpendicular line that I wanted. Why is it not getting drawn?
Upvotes: 1
Views: 204
Reputation: 385500
You're using these two lines to set up the path for your “perpendicular line”:
[xAxis moveToPoint:CGPointMake(width, height/2 - 150)];
[xAxis addLineToPoint:CGPointMake(width, height/2 + 150)];
The problem is that the X coordinate of both points is the right edge of your view. Perhaps you want it to be at the center of your view:
CGFloat xMid = CGRectGetMidX(rect);
[xAxis moveToPoint:CGPointMake(xMid, height/2 - 150)];
[xAxis addLineToPoint:CGPointMake(xMid, height/2 + 150)];
Upvotes: 1
Reputation: 4749
try alter these two lines
[xAxis setLineWidth:2];
[[UIColor grayColor] setStroke];
Upvotes: 0
Reputation: 5112
What color is the background of your view? You should make sure it's not too close to greyColor
or you won't see it even if it's there.
Upvotes: 0