gpt4 book ai didi

ios - 在我的 UINavigationBar 中为我的标题添加图像而不是标题

转载 作者:行者123 更新时间:2023-12-01 19:07:04 25 4
gpt4 key购买 nike

我的 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。相反,它被拉伸(stretch)并超过了导航栏中的 < 返回按钮。有刻度方法吗?

最佳答案

采用

myImageView.contentMode = UIViewContentModeScaleAspectFill;

这样imageview就不会被拉伸(stretch),并保持它的外观

关于ios - 在我的 UINavigationBar 中为我的标题添加图像而不是标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18998961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com