![](/img/trans.png)
[英]How to hide UINavigationBar from a UINavigationController?
[英]Hide the title from UINavigationBar?
有沒有辦法隱藏UINavigationBar中的標題視圖?
self.navigationItem.titleView = [[UIView alloc] initWithFrame:CGRectZero]; self.title = @"Home";
設置為nil將不會如文檔中所述那樣工作:如果此屬性值為nil,則當接收器為頂部項目時,導航項的標題將顯示在導航欄的中心。 如果將此屬性設置為自定義標題,則會顯示該屬性而不是標題。
titleView是一個UIView:
titleView當此項目是頂部項目時,導航欄中心顯示的自定義視圖。
@property(nonatomic, retain) UIView *titleView
所以我認為你可以試試這個:
[titleView setHidden:YES];
另一個保留后退按鈕的選項(如下所示: https : //stackoverflow.com/a/23113326/1156575 ):
[self.navigationController.navigationBar setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor clearColor]
}];
對我來說,swift中的解決方案需要在我的導航欄子類中:
self.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.clearColor()]
標題清晰,標題消失。 正如Josema所描述的,您也可以通過導航控制器訪問導航欄來執行此操作:
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.clearColor()]
這對我有用:
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.clear]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.