我的 UINavigationitem 的 TitleView 在 ios 6 中得到扩展

2023-12-03

在我的应用程序中,我在 uinavigation 项目上应用了图像。它在 iOS 5 中运行良好,但在 iOS 6 上得到扩展。我的导航栏中没有左栏或右栏按钮项目。我搜索了太多但找不到答案。

这是我的代码:

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

图像显示如下:

screenshot

它应该像下图一样显示,但在 iOS 6 中显示为展开的,在 iOS 5 中效果很好。

结果是:

result screenshot


我从 iOS 6 开始遇到同样的问题,并找到了最疯狂的解决方法:

再创建一个相同尺寸的 UIImageView。然后将 navigationImage 作为子视图添加到其中。就我而言,这将阻止自动调整大小。

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

如果有人找到正确的解决方案或解释,请发布。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我的 UINavigationitem 的 TitleView 在 ios 6 中得到扩展 的相关文章

随机推荐