Johannes
Johannes

Reputation: 325

UIButton scale vector graphic

I use vector graphics in my app and would like the image to be bigger. Unfortunately all posts I found on this just scaled the image, not using the through vector graphics available higher resolution.

photoButton = [[UIButton alloc] initWithFrame:CGRectMake(width/3.0*2.0-15,
                                                                       15,
                                                                       width/3.0,
                                                                       height/3.0)];
    [photoButton setImage:[UIImage imageNamed:@"Photo"] forState:UIControlStateNormal];
    [photoButton addTarget:self action:@selector(photo) forControlEvents:UIControlEventTouchUpInside];

Any ideas?

Upvotes: 0

Views: 743

Answers (1)

Fogmeister
Fogmeister

Reputation: 77641

Ah, what you're seeing is a result of how the vector images are used in ios and os x. They are not stored as vector images in the compiled bundle. The vector image is used, at compile time, to create all the required standard and retina versions of the image. These are then stored as png files in the bundle and the png file for the screen resolution (standard, 2x, 3x retina) are used to display them.

What you probably want is to use a resizable image. For this you can't use vector images you have to provide a png. Then you can "slice" the image into resizable and non-resizable sections.

For instance you can create a button background image that will resize to the button dimensions and keep the corners nice and rounded by making sure the corners are not distorted.

Take a look at the "show slicing" options in the asset catalog in Xcode.

Upvotes: 2

Related Questions