In Paintcode 2, I have a circle inside a frame inside a canvas.
The constraints on the circle are set like this:
To get the circle to size up and not become an ellipse, I have to
Is there any way around this type of code?
-(void)drawRect:(CGRect)rect {
if (rect.size.width > rect.size.height) {
rect.origin.x = (rect.size.width - rect.size.height) * .5f;
rect.size.width = rect.size.height;
} else {
rect.origin.y = (rect.size.height - rect.size.width) * .5f;
rect.size.height = rect.size.width;
}
NSLog(@"Frame=%@", NSStringFromCGRect(rect));
[CircleDraw drawCircleWithFrame:rect];
}
150x120
10, 10, 100, 100
frame
, type rectangle: 10, 10, 150, 100
min(frame.height, frame.width)
position
(below)smallestSide
to both height and width of the ellipseposition
to the position of the ellipse makePoint(
frame.x+(frame.width-smallestSide)*0.5,
frame.y+(frame.height-smallestSide)*0.5
)
- (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 had the help of Matt Dunik at PaintCode to figure this out, but the solution is actually very straightforward.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With