Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain aspect ratio when resizing PaintCode generated view?

I'm using PaintCode to generate a stylekit for my xamarin.ios app. I have a simple logo that I pasted into PaintCode from illustrator. Everything looks fine, I have a frame and the generated draw method takes a rect.

At one point I had it resizing in my storyboard but it doesn't maintain the aspect ratio so obviously the logo looked wrong depending on the size of the UIView.

How can I add variables/expressions to paintcode so that the generated code automatically maintains the aspect ratio when the UIView is resized?

Thanks.

like image 679
jmichas Avatar asked Jul 12 '15 14:07

jmichas


People also ask

How do you maintain the aspect ratio of a shape?

To maintain the ratio of the height and width whenever you resize a shape, enable the constrain proportions option. While Constrain Proportions is enabled, when you resize the shape, it will won't stretch the shape, but keep the height and width in the shape's original proportions.

Why is it important to maintain aspect ratios when resizing an image?

When scaling your image, it's crucial to maintain the ratio of width to height, known as aspect ratio, so it doesn't end up stretched or warped. If you need a specific width and height, you may need a mixture of resizing and cropping to get the desired result.


1 Answers

This is possible with Variables. Try creating two Variables like this:

  1. Numeric “Width” with a value for example 100.
  2. Expression “Height” with a value width / 2. This would maintain a ratio of 2:1, change as you need.

Then attach these two to your Frame object on Width and Height attributes. After that, the generated method will take only one numeric parameter – the Width:

- (void)drawMyCanvasWithWidth: (CGFloat)width;

Should look like on this image:

Preview

Then just pass your desired width and the height will be calculated automatically.


It would also be possible to maintain CGRect parameter of the method and to find fitting rectangle using Variables. I’ll add that if you ask.

like image 112
Tricertops Avatar answered Oct 11 '22 09:10

Tricertops