UI导航栏标题
我试图使用 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",但它总是显示在那里:
如果我这样做 self.title = nil,那么一切都消失了...如何从导航栏中消除这个神秘的标题并只使用我创建的 UILabel。
I am trying to use a UILabel to replace the title at the UINavigationBar, the code is as follows:
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];
The problem is that, how do I remove the original title of the bar? I didn't declare any self.title = @"title", but it always shows it there:
If I do self.title = nil, then everything is gone... How do eliminate this mysterious title from the navbar and just use the UILabel I created.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你为什么不直接做 self.title = @"" 呢?
编辑:试试这个?
Why don't you just do self.title = @""?
EDIT: Try this?
使用
self.navigationItem.titleView = nav_title;
而不是将标签添加为子视图。Use
self.navigationItem.titleView = nav_title;
instead of adding your label as a subview.使用这个:
Use this: