gpt4 book ai didi

iphone - UI导航栏标题

转载 作者:行者123 更新时间:2023-12-03 20:26:01 27 4
gpt4 key购买 nike

我正在尝试使用 UILabel 来替换 UINavigationBar 处的标题,代码如下:

UINavigationBar *bar = [self.navigationController navigationBar];
[bar setBackgroundColor:[UIColor blackColor]];

UILabel * nav_title = [[UILabel alloc] initWithFrame:CGRectMake(80, 2, 220, 25)];
nav_title.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
nav_title.textColor = [UIColor whiteColor];
nav_title.adjustsFontSizeToFitWidth = YES;
nav_title.text = title;
nav_title.backgroundColor = [UIColor clearColor];
[bar addSubview:nav_title];
[nav_title release];

问题是,如何去掉原来的栏标题呢?我没有声明任何 self.title = @"title",但它总是显示在那里:

enter image description here

如果我这样做 self.title = nil,那么一切都消失了...如何从导航栏中消除这个神秘的标题并只使用我创建的 UILabel。

最佳答案

你为什么不直接做 self.title = @""呢?

编辑:试试这个?

UINavigationBar *bar = [self.navigationController navigationBar];
[bar setBackgroundColor:[UIColor blackColor]];

UILabel * nav_title = [[UILabel alloc] initWithFrame:CGRectMake(80, 2, 220, 25)];
nav_title.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
nav_title.textColor = [UIColor whiteColor];
nav_title.adjustsFontSizeToFitWidth = YES;
nav_title.text = title;
self.title = @"";
nav_title.backgroundColor = [UIColor clearColor];
[bar addSubview:nav_title];
[nav_title release];

关于iphone - UI导航栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5928851/

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