I know how to draw lines and shapes with CGPath
s . But I couldn't figure out how to draw this symbol for a circuit diagram
What code should I write to get that half circle shape?
This is what I have so far:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 5.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 60, 80);
CGContextAddLineToPoint(context, 120, 80);
CGContextMoveToPoint(context, 120, 80);
CGContextAddArc(120,80,M_PI,M_PI/2);
CGContextMoveToPoint(context, 200, 80);
CGContextAddLineToPoint(context, 300, 80);
CGContextStrokePath(context);
}
You could create a
UIBezierPath
, e.g. something like:You could have your view controller just create a
CAShapeLayer
and add it to your view'slayer
.If you wanted to do it in the
drawRect
of aUIView
subclass you could,stroke
this path:Or, as your revised question suggests, if you're more comfortable with CoreGraphics, you could do that, too: