[英]Custom navigation bar doesn't change / show title
我在情節UINavigationBar
中添加了UINavigationBar
。 我的應用程序必須動態更改欄的標題。 首先,我嘗試在情節提要中更改標題並運行該應用程序,但標題沒有出現。 然后,我嘗試通過代碼添加標題。 首先,我將IBOutlet
從UINavigationItem
連接到我的@interface
並嘗試添加如下標題:
_navibarTitle.title = @"Something";
它也沒有解決,標題沒有出現。 由於我的應用程序必須隱藏UINavigationController
的默認欄並使用自定義欄,因此我什至嘗試了以下操作:
self.navigationItem.title = @"Something";
和這個:
self.navigationController.navigationItem.title = @"HI";
他們也沒有解決。 (我知道最后兩個將不起作用,因為默認的導航欄被隱藏了)。 所以我想我沒主意了。 有什么事嗎
為屏幕或導航欄設置標題的簡單最佳方法是:
self.title = @"Your Title"
它將自動在導航欄上顯示您的標題。 您也可以從該問題獲得幫助。
其他執行相同操作的方法:
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
navLabel.backgroundColor = [UIColor clearColor];
navLabel.textAlignment = NSTextAlignmentCenter;
navLabel.text = @"Your Title";
self.navigationItem.titleView = navLabel;
我希望這會起作用。
嘗試這個:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont systemFontOfSize:20];
self.navigationItem.titleView = titleLabel;
titleLabel.text = @"Something";
[titleLabel sizeToFit];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.