Here is your code modified to show what I mean (unverified):
- (void)drawRect:(CGRect)rect {
static CGFloat length = 100;
static CGFloat rounding = 5;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1].CGColor);
CGContextMoveToPoint(context, rounding * 2, 0);
CGContextAddLineToPoint(context, length - rounding, 0);
CGContextAddArcToPoint(context, length, 0, length, rounding, rounding * 2);
CGContextAddLineToPoint(context, length, length - rounding);
CGContextAddArcToPoint(context, length, length, length - rounding, length, rounding * 2);
CGContextAddLineToPoint(context, rounding, length);
CGContextAddArcToPoint(context, 0, length, 0, length - rounding, rounding * 2);
CGContextAddLineToPoint(context, 0, rounding);
CGContextAddArcToPoint(context, 0, 0, rounding, 0, rounding * 2);
CGContextFillPath(context);
}
I also wonder about 10 in your code. As far as I can see, they should be 5 seconds instead. In any case, itβs easier to use UIBezierPath, as others have shown (the solution of the layer works, but obviously this will not work if, for example, you want to draw something below a rounded rectangle and something above).