【问题标题】:Trying to set oversized image as navigation bar title. Width refuses to adjust试图将超大图像设置为导航栏标题。宽度拒绝调整
【发布时间】:2013-10-21 00:16:36
【问题描述】:

我有一个图像/横幅,我想将其用作导航栏的标题。图像的分辨率为 720x227 像素。我把图片扔到了UIButton 我设置为 79x25 的框架中:

UIButton* titleImage = [[UIButton alloc] initWithFrame:CGRectMake(0,0,79,25)];
[titleImage setBackgroundImage:[UIImage imageNamed:@"title.png"] forState:UIControlStateNormal];
[titleImage setUserInteractionEnabled:NO];
self.navigationItem.titleView = titleImage;

高度调整完美。然而,宽度卡在 250 像素左右,并且无论我输入什么数字都拒绝调整,如下所示。谁能明白为什么?让我知道您还需要查看哪些其他代码。

编辑:我也试过剪掉 UIButton 并简单地将它扔到一个图像视图中,如下所示:

UIImageView* titleImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 25)];
[titleImage setImage:[UIImage imageNamed:@"title.png"]];
self.navigationItem.titleView = titleImage;

但是,问题仍然存在。

【问题讨论】:

    标签: ios objective-c navigationbar


    【解决方案1】:

    我建议您调整图像的大小,使其适合导航栏,当只显示缩小的图像时,没有理由将如此大的图像加载到内存中。

    您的应用在启动时会加载得更快。

    【讨论】:

    • 我同意,我目前正在处理这个问题。不过,我还是想知道为什么我无法调整宽度。
    • 它目前正在缩小您的图像以适应。如果你 [titleImage setContentMode:UIViewContentModeScaleAspectFit];它会缩放以适应。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2018-04-14
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2018-07-21
    相关资源
    最近更新 更多