Change the font of a UIBarButtonItem

前端 未结 16 1023
春和景丽
春和景丽 2020-12-07 09:18

\"UIToolbar

I have a UIBarButtonItem in my UIToolbar titled

16条回答
  •  有刺的猬
    2020-12-07 10:01

    This is the right way: declare your barButtonItem (in this case rightBarButtonItem) and add it setTitleTextAttributes.

    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Go!", style: .plain, target: self, action: #selector(yourFuncDestination))
    

    after you can add title attributes

    navigationItem.rightBarButtonItem?.setTitleTextAttributes([.font : UIFont.systemFont(ofSize: 18, weight: .bold), .foregroundColor : UIColor.white], for: .normal)
    

    you can change the size, the weight (.bold, .heavy, .regular etc.) and the color how you prefer... Hope this help :)

提交回复
热议问题