【问题标题】:Add an image instead of a title to my title in my UINavigationBar在我的 UINavigationBar 中为我的标题添加图像而不是标题
【发布时间】:2013-09-25 07:38:11
【问题描述】:

我的 uiviewcontroller 中有以下代码嵌入在 uinavigationcontroller 中。

在 viewDidLoad 中:

[self addLogo];

下面:

- (void) addLogo
{
    UIImage *image = [UIImage imageNamed:@"logoblack.png"];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:image];

    myImageView.frame = CGRectMake(0, 0, 30, 30);
    myImageView.layer.cornerRadius = 5.0;
    myImageView.layer.masksToBounds = YES;
    myImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    myImageView.layer.borderWidth = 0.1;

   self.navigationItem.titleView = myImageView;
}

我拥有的图像是 434 x 434,但我希望它是 30 x 30。相反,它被拉伸并超过了导航栏中的

【问题讨论】:

  • 为什么不在预览应用程序中缩放和调整图像大小并添加 30X30 帧 - 不要认为它很复杂
  • 是的,我会这样做,只是想了解更多有关 iOS api 的信息
  • 你有没有尝试改变titleView的contentMode。对 UIViewContentModeBottom 说。

标签: ios uinavigationcontroller uinavigationbar ios7


【解决方案1】:

使用

myImageView.contentMode = UIViewContentModeScaleAspectFill;

这样图像视图就不会被拉伸,并保持它的纵横比

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    相关资源
    最近更新 更多