简体   繁体   English

如何在多行项目中创建带有多行项目的UITabBar

[英]How to make a UITabBar with multi-line itemTitle in swift 4

currently I'm working in an iOS project in swift. 目前,我正在迅速从事iOS项目。 In my project, I have UITabBarController, which contains five items. 在我的项目中,我有UITabBarController,其中包含五个项目。 Now it is working fine no issue. 现在,它工作正常,没有问题。 But now I need to change the title to a bigger title. 但是现在我需要将标题更改为更大的标题。 But after changing the title, the item title is not showing fully or in two lines. 但是,更改标题后,项目标题未完整显示或两行显示。 What I need is to list the title name in two lines. 我需要在两行中列出标题名称。 Is there any way to do that? 有什么办法吗? I checked all the codes. 我检查了所有代码。 Please help me. 请帮我。

As per my knowledge you can't achieve this with default tabor item. 据我所知,您无法使用默认tabor项目来实现此目的。 You must add custom view and design tabs by your own which explained below. 您必须自己添加自定义视图和设计选项卡,如下所述。

  • Write a method like addCustomTabbar() in your UITabBarController subclassed class and call addCustomTabbar() method in awakeFromNib() . 在您的UITabBarController子类化类中编写类似addCustomTabbar() addCustomTabbar()方法,并在awakeFromNib()调用addCustomTabbar()方法。 - Hide default tab bar with self.tabBar.isHidden = true . -使用self.tabBar.isHidden = true隐藏默认标签栏。 This hides your default tab bar. 这将隐藏您的默认选项卡栏。
  • Create your own UIView with frame is equal to tab bar frame like let tabbarView = UIView(frame: tabBar.frame) . 使用frame创建自己的UIView等于tab bar框架,如let tabbarView = UIView(frame: tabBar.frame)
  • From here onwards create a UIButton object with respective frame and add to your custom view ie tabbarView like below. 从这里开始,创建带有相应框架的UIButton对象,并将其添加到您的自定义视图(即tabbarView如下所示。

    let btn = UIButton(frame: CGRect(x: 0, y: 0, width: individualWidth, height: Int(custom_tab_view.frame.height))) 让btn = UIButton(frame:CGRect(x:0,y:0,width:单独宽度,高度:Int(custom_tab_view.frame.height))))

As every UIButton had titleLabel , you can set number of lines property of the titleLabel is zero and text wrap is wordWrap . 由于每一个UIButtontitleLabel ,您可以设置的行属性的数量titleLabel是零和文本换行是wordWrap In this way, you can achieve title with multiple lines. 这样,您可以用多行标题。

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

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