繁体   English   中英

隐藏UINavigationBar的标题?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM