您现在的位置是:首页 > 电脑 > 

如何在swift中以编程方式显示导航栏中的tittle(How to show the tittle in navigation bar programmatically in swift)

2025-07-18 16:25:00
如何在swift中以编程方式显示导航栏中的tittle(How to show the tittle in navigation bar programmatically in swift) 我只是尝试扩展导航栏的高度...我尝试下面的代码,它的工作正常....但它无法显示标题? 我试过self.title =“”和self.navigationitem.t
如何在swift中以编程方式显示导航栏中的tittle(How to show the tittle in navigation bar programmatically in swift)

我只是尝试扩展导航栏的高度...我尝试下面的代码,它的工作正常....但它无法显示标题? 我试过 =“”和 =“”也......

= UIColor.blue // = "Instrumental" = "Instrumental" = [SForegroundColorAttributeame:UIColor.white] let backButton = UIButton(type: .custom) backButton.frame = CGRect(x: 80, y: 15, width: 0, height: 0) backButton.setImage(UIImage(named:"vertical-dots (1)"), for: .normal) // backButton.addTarget(self, action: #selector(ViewController.backButton(_:)), for: .TouchUpInside) navBar.addSubview(backButton) func setavBarToTheView() { frame = CGRect(x:0, y:0, width:420, height:60) // Here you can set you Width and Height for your navBar backgroundColor = (UIColor.blue) self.view.addSubview(navBar) }

I just try to extend my height of navigation bar...I tried that code below, Its working fine....but it can't able to show the title? I tried ="" and ="" also......

= UIColor.blue // = "Instrumental" = "Instrumental" = [SForegroundColorAttributeame:UIColor.white] let backButton = UIButton(type: .custom) backButton.frame = CGRect(x: 80, y: 15, width: 0, height: 0) backButton.setImage(UIImage(named:"vertical-dots (1)"), for: .normal) // backButton.addTarget(self, action: #selector(ViewController.backButton(_:)), for: .TouchUpInside) navBar.addSubview(backButton) func setavBarToTheView() { frame = CGRect(x:0, y:0, width:420, height:60) // Here you can set you Width and Height for your navBar backgroundColor = (UIColor.blue) self.view.addSubview(navBar) }

最满意答案

您似乎手动将UIavBar添加到视图中。 当您执行此操作时,将视图控制器放入导航控制器时会丢失所有自动功能。

要设置导航栏的标题,您还需要创建UIavigationItem并将其设置为导航栏的items属性。

如果将视图控制器放在导航控制器中,事情会变得非常简单。 然后,您将获得所有默认行为,包括标准导航栏,而无需执行添加自己的所有工作。

It appears that you are manually adding a UIavBar to the view. When you do that you lose all of the automatic features when you put your view controller into a navigation controller.

To set the title of your nav bar you need to also create a UIavigationItem and set it to the nav bar's items property.

Things really would be a lot simpler if you put your view controller in a navigation controller. Then you get all of the default behavior including a standard nav bar without the need to do all the work of adding your own.

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/697374.html

相关标签:无
上传时间: 2023-08-27 09:48:22
留言与评论(共有 9 条评论)
本站网友 tianjing
17分钟前 发表
for
本站网友 隆美尔巨额黄金之谜
25分钟前 发表
action
本站网友 李子的功效和作用
21分钟前 发表
Its working fine....but it can't able to show the title? I tried ="" and ="" also...... = UIColor.blue // = "Instrumental" = "Instrumental" = [SForegroundColorAttributeame
本站网友 运筹学与控制论
14分钟前 发表
.custom) backButton.frame = CGRect(x
本站网友 九江房产网
13分钟前 发表
您还需要创建UIavigationItem并将其设置为导航栏的items属性
本站网友 双井百环家园
18分钟前 发表
它的工作正常....但它无法显示标题? 我试过 =“”和 =“”也...... = UIColor.blue // = "Instrumental" = "Instrumental" = [SForegroundColorAttributeame
本站网友 青岛二手房网
20分钟前 发表
.normal) // backButton.addTarget(self
本站网友 尚城摄会
13分钟前 发表
0