【问题标题】:My UINavigationitem's TitleView getting expanded in ios 6我的 UINavigationitem 的 TitleView 在 ios 6 中得到扩展
【发布时间】:2012-12-21 10:46: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;

图像显示如下:

它应该显示为下图,但在 iOS 6 中显示为展开式,在 iOS 5 中运行良好。

结果是:

【问题讨论】:

  • 给出一些代码(如何添加图像)和截图!

标签: ios uinavigationitem titleview


【解决方案1】:

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

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

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

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

【讨论】:

  • 谢谢 Vanja 它解决了我的问题,但我想知道那里有什么问题
  • 尝试设置原图的contentMode:navigationImage.contentMode = UIViewContentModeCenter;
  • 不,titleView 既不居中也不适合 imageView 框架。
【解决方案2】:

我的项目中有以下代码,在 iOS 5 和 iOS 6 下运行良好。你可以试试这个:

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

另外,请确保图片同时具有@2x 和常规尺寸。

【讨论】:

  • 我使用了这个解决方案,但结果保持不变,而且我总是有@2x 图像,因为我的最低部署目标是 iOS 5.0。如果你想看到我在上面展示给你的结果。
  • 嗯,这很有趣。您能否验证常规图像和@2x 图像的名称相同(可能是错字?)并且常规图像和@2x 图像实际上是正确的尺寸(在我的情况下,我有一个 120x20 的常规图像和 240x40对于@2x)?
  • 我总是以双倍分辨率拍摄图像,因为这里的图像尺寸是 195 × 68 像素,但图像视图框架是 98 x 34 像素
猜你喜欢
  • 1970-01-01
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多