简体   繁体   English

在某些情况下如何设置具有标题视图的导航项目的标题

[英]How to set title of navigationitem which have titleview for some conditions

I have a navigationItem with a titleView . 我有一个navigationItemtitleView Now in some conditions I want to use the title property for that navigationItem . 现在在某些情况下,我想为该navigationItem使用title属性。 How to do that? 怎么做? Any idea? 任何想法?

Here is what I have tried, however is not working: 这是我尝试过的,但是没有用:

self.revealViewController().navigationItem.titleView = UIView.init()

self.revealViewController().navigationItem.title = "My Item"

在设置标题之前,需要将titleView设置为nil。

在您的ViewController的viewdidload中,您可以设置标题,例如

  self.title = "your title"
UIView* titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
//titleView.backgroundColor=[UIColor redColor];

self.navigationItem.titleView=titleView; self.navigationItem.titleView = titleView;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置navigationItem titleView的按钮? - How to set button for navigationItem titleView? 为所有navigationcontroller和navigationitem设置titleview - Set titleview for all navigationcontroller and navigationitem 如何设置navigationItem.titleView图像水平居中? - How to set navigationItem.titleView image horizontal center? iOS 11 navigationItem.titleView 宽度未设置 - iOS 11 navigationItem.titleView Width Not Set 如何设置NavigationItem / NavigationBar的标题 - How do I set the title of the NavigationItem/NavigationBar 如何在屏幕之间保留navigationItem.titleView? - How to persist navigationItem.titleView between screen? 我如何将navigationItem.titleView放在左右栏按钮项的后面 - how do I have the navigationItem.titleView to be behind left and right bar button item 导航项.titleView中标题和字幕的字体大小未更改 - Font size is not changed for title and subtitle in navigationItem.titleView 如何将UISearchController的searchBar设置为不是tableHeaderView或navigationItem.titleview的视图? - How do I set the UISearchController's searchBar to a view that isn't the tableHeaderView or navigationItem.titleview? NavigationItem titleView在左侧出现一段时间然后移动到Center - NavigationItem titleView is coming at left side for some time then move to Center
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM