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

标签 ios uinavigationitem titleview

在我的应用程序中,我在 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 作为 subview 添加到其中。在我的例子中,这将阻止自动调整大小。

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

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

关于ios - 我的 UINavigationitem 的 TitleView 在 ios 6 中得到扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988642/

相关文章:

android - 如何获取联系人并使用 flutter 打印它们?

ios - 在滚动某些项目之前, self 调整单元格无法工作

ios - 在 iOS 11 上从右到左显示大标题

ios - UINavigationBar TitleView 带副标题

ios - 多个导航标题文本 - swift

ios - XCUITesting 不断使我的应用程序崩溃

javascript - 如何在 phonegap 的 ios7 之上添加永久线路

iphone - 标签栏中的 UINavigationButton - 可能被拒绝?

iphone - 下一个和上一个按钮就像 iPhone 中的邮件应用程序

cocoa-touch - UINavigationController 上的自定义 titleView 动画不正确