- Create canvas,
150x120 - Create an ellipse,
10, 10, 100, 100 - Create a new variable
frame , enter the rectangle: 10, 10, 150, 100 - Create a new smallestSide expression:
min(frame.height, frame.width) - Make an expression called
position (below) - Drag
smallestSide to the height and width of the ellipse - Drag
position to ellipse position
position (expression) makePoint( frame.x+(frame.width-smallestSide)*0.5, frame.y+(frame.height-smallestSide)*0.5 )
Output - (void)drawCanvas1WithFrame: (CGRect)frame { //// Variable Declarations CGFloat smallestSide = MIN(frame.size.height, frame.size.width); CGPoint position = CGPointMake(frame.origin.x + (frame.size.width - smallestSide) * 0.5, frame.origin.y + (frame.size.height - smallestSide) * 0.5); //// Oval Drawing UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(position.x, position.y, smallestSide, smallestSide)]; [UIColor.grayColor setFill]; [ovalPath fill]; }
NOTE. . I was helped by Matt Dunik at PaintCode to figure this out, but the solution is actually very simple.
source share