UINavigationBar TitleView with subtitle

后端 未结 9 899
一生所求
一生所求 2021-01-01 21:09

I want a titleView inside my UINavigationBar which has two lines of text instead of only one

My current implementiation works well when I have a \"Back\"-Button and

9条回答
  •  旧巷少年郎
    2021-01-01 21:38

    https://www.reddit.com/r/swift/comments/3izq7b/style_guidelines_for_navigation_bar_prompts/

    extension UINavigationItem {
    
        //Make the title 2 lines with a title and a subtitle
        func addTitleAndSubtitleToNavigationBar (title: String, subtitle: String) {
            var label = UILabel(frame: CGRectMake(10.0, 0.0, 50.0, 40.0))
            label.font = UIFont.boldSystemFontOfSize(14.0)
            label.numberOfLines = 2
            label.text = "\(title)\n\(subtitle)"
            label.textColor = UIColor.blackColor()
            label.sizeToFit()
            label.textAlignment = NSTextAlignment.Center
            self.titleView = label
        }
    }
    

提交回复
热议问题