문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top