How do you set the font size on a UIBarButtonItem?

前端 未结 5 2017
旧巷少年郎
旧巷少年郎 2021-02-03 19:42

I can\'t find a way to set the font size of the title in a custom UIBarButtonItem. The only way I can think of getting around this is to set it as an image which I would like to

5条回答
  •  眼角桃花
    2021-02-03 19:56

    Swift5:

        let item = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(self.onItemTapped))
        let font:UIFont = UIFont(name: "", size: 18) ?? UIFont()
        item.setTitleTextAttributes([NSAttributedString.Key.font: font], for: UIControl.State.normal);
    

提交回复
热议问题