My UINavigationitem's TitleView getting expanded in ios 6
Asked Answered
T

2

4

In my app I have applied an image on uinavigation item. It is running fine in iOS 5 but getting expanded on iOS 6. I have no left or right bar button item in navigation bar. I searched too much but couldn't find answer.

Here is my code:

UIImageView *navigationImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 98, 34)];
navigationImage.image=[UIImage imageNamed:@"topNav-logo.png"];
self.navigationItem.titleView=navigationImage;

and image shows like this:

screenshot

It should be displayed like lower image but it is displayed like expanded in iOS 6 it works good in iOS 5.

The result is:

result screenshot

Tendon answered 21/12, 2012 at 10:46 Comment(1)
Give some code (how you add the image) and a screenshot !Highams
P
5

I have the same issue starting at iOS 6, and found the craziest workaround:

Create one more UIImageView of the same dimension. Then add the navigationImage as a subview to that. In my case this will prevent the auto resizing.

UIImageView *workaroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 98, 34)];
[workaroundImageView addSubview:navigationImage];
self.navigationItem.titleView=workaroundImageView;

If anyone finds a proper solution or an explanation please post it.

Pommel answered 23/1, 2013 at 12:57 Comment(3)
Thanks Vanja It solved my problem but i want to know what was problem thereTendon
Try setting the contentMode of the original image: navigationImage.contentMode = UIViewContentModeCenter;Philippine
No, that neither centers the titleView nor fits it to the imageView frame.Haiti
V
0

I have the following code in my project, and works fine under iOS 5 and iOS 6. Can you try this:

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topNav-logo.png"]];

Also, be sure to have both @2x and regular sizes of the image.

Valle answered 21/12, 2012 at 12:3 Comment(3)
I used this solution but the result remains same as well as i always have @2x images because my minimum deployment target is iOS 5.0. The result if you want to see i show to you at above.Tendon
Hm, that's interesting. Can you please verify that the regular and @2x images are named the same (maybe a typo?) and that the regular and @2x images are actually the correct dimensions (in my case I have a 120x20 for the regular image and 240x40 for the @2x)?Valle
I always take images in double resolution as here image dimension is 195 × 68 pixels but the image view frame is 98 x 34 pixalTendon

© 2022 - 2024 — McMap. All rights reserved.