gpt4 book ai didi

Iphone/Ipad 添加图像和文本到导航标题

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:37 24 4
gpt4 key购买 nike

我只是想将图像和文本添加到 navigationItem 标题。这就是我正在做的,但它只显示图像而不显示标题。这似乎很容易。

示例 (

self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_small_white.png"]] autorelease];
self.navigationItem.title = @"Company";

最佳答案

这是我的代码:

UIView *myView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 300, 30)]; 
UILabel *title = [[UILabel alloc] initWithFrame: CGRectMake(40, 0, 300, 30)];

title.text = NSLocalizedString(@"My Title", nil);
[title setTextColor:[UIColor whiteColor]];
[title setFont:[UIFont boldSystemFontOfSize:20.0]];

[title setBackgroundColor:[UIColor clearColor]];
UIImage *image = [UIImage imageNamed:@"MyLogo.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;

[myView addSubview:title];
[myView setBackgroundColor:[UIColor clearColor]];
[myView addSubview:myImageView];
self.navigationItem.titleView = myView;

关于Iphone/Ipad 添加图像和文本到导航标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4411886/

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