How to set the title of UIToolBar?

后端 未结 8 1153
独厮守ぢ
独厮守ぢ 2021-02-01 07:09

How can I set the title of UIToolBar such that it looks the same as the title in UINavigationBar?

I tried to use a button with plain style, it looks ok, but it will be

8条回答
  •  难免孤独
    2021-02-01 07:38

    Swift 5 version of Rayfleck's great answer:

    let titleButton = UIBarButtonItem(title: "My Title", style: .plain, target: nil, action: nil)
    titleButton.isEnabled = false
    titleButton.setTitleTextAttributes([.foregroundColor : UIColor.black], for: .disabled)
    

    Add this button to the toolbar as normal.

提交回复
热议问题