Is there a way to change the width and insertion of a Bar Button element in a navigation element?

I wanted to use a retina resolution image (40x40p) on a panel element on my MVC navigation element. When I set the image, it looked stretched horizontally, as expected:

Stretched navigation item button image

Note. I also have an image of a toolbar button that is in retina resolution (60px60p), as required by Apple spec . It was also stretched when the size parameters had default values, that is, width = 0, insertion; m = 0, B = 0, L = 0, r = 0:

enter image description here

However, unlike the navigator element, in the case of the toolbar, I could successfully change these values ​​from IB. When I set the width = 30, and the inserts t = 5, b = 5, l = 5, r = 5, the toolbar button works fine:

Perfectly scaled hi-res toolbar button image

When I used the size inspector and tried to set the width and insertion values ​​of the navigation bar button element, this did not seem to have an effect. The image of the mechanism still looked stretched.

I also tried to create a panel button element in the code navigation element and set the width and insertion there, it did not work either:

UIImage *image = [UIImage imageNamed:@" 073-Setting@2x.png "]; //-------------------------------------------------------------------- // This line had no effect for a bar button item on a navigation item: image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(5.0,5.0,5.0,5.0)]; //-------------------------------------------------------------------- UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(handleBack:)]; //-------------------------------------------------------------------- // This line had no effect for a bar button item on a navigation item: button.width = 30; //-------------------------------------------------------------------- 

Any ideas that I am doing something wrong, or it seems like a mistake. My deployment goal is iOS 5.0.

0
source share
1 answer

Now I understand the cause of this problem. I did not know that I needed to pack both regular and hi-resolution (@ 2x) images in the application bundle. I naively thought to include a hi-res image and expect it to work. Since I only have an iPhone story board, including 20 and 40 pixel versions of each image in the kit, I fixed my problem.

As a result, there is no need to wave with the width or insertion of buttons. This issue has been fixed.

0
source

Source: https://habr.com/ru/post/1380082/


All Articles