My UINavigationitem's TitleView getting expanded in ios 6

こ雲淡風輕ζ 提交于 2019-12-01 19:06:23

问题


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. Help me if you know the 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- ![enter image description here][1]

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

Thanks in advance

@Marko Nikolovski- the result is ![enter image description here][2]


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13988642/my-uinavigationitems-titleview-getting-expanded-in-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!