gpt4 book ai didi

iphone - 如何在特定位置添加 uinavigationbar 中的项目?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:15 26 4
gpt4 key购买 nike

我正在为 iphone 开发一个应用程序,其中我有一些关于在特定位置的导航栏中添加多个 UILabel 的问题。

我想要的是下面的图片

enter image description here

在上图中,有一个返回栏按钮和一个 imageview,如箭头标记所示。除此之外,所有的白框都是为了在导航栏中显示不同的 UILabels。导航栏中只有一个UIImageView和一个左栏按钮。现在的问题是我不知道如何在导航栏中的特定位置添加多个 UILabel

到目前为止,我所做的是只添加按钮和带有右栏按钮数组或左栏按钮数组的 UIImageView,但这只会按顺序添加项目。

所以任何人都可以指导我如何在特定位置添加 UILabels 或任何其他项目..

最佳答案

您可以添加多个 UIlabel 或图像,如下图所示:-

enter image description here

这可以使用下面的代码来完成,您可以更改 Label 和 imageView 框架并根据您的要求放置

- (void)viewDidLoad
{

UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];

UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = @"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];

label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = @"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];


UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:@"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];

self.navigationItem.titleView = btn;

}

关于iphone - 如何在特定位置添加 uinavigationbar 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958913/

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