UINavigationBar标题 [英] UINavigationBar title

查看:111
本文介绍了UINavigationBar标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];

问题在于,如何删除栏的原始标题?我没有宣布任何self.title = @title,但它总是在那里显示:

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:

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

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.

推荐答案

你为什么不做自我.title = @?

Why don't you just do 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];

这篇关于UINavigationBar标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆