更改 UIBarButtonItem 的字体颜色 [英] Changing font color of UIBarButtonItem

查看:64
本文介绍了更改 UIBarButtonItem 的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将右侧栏按钮项的字体颜色更改为紫色,但它仍然显示为白色.我已经咨询过这个问题和这个问题.我该如何解决这个问题?

I tried to change the font color of the right bar button item to purple, but it still shows up as white. I've consulted this question and this question. How do I fix this?

代码

let sortButton = UIButton(frame: CGRect(x: 0, y: 0, width: 34, height: 15))
    sortButton.setTitle("SORT", for: .normal)
    sortButton.titleLabel?.tintColor = UIColor.myMusicPurple
    sortButton.tintColor = UIColor.myMusicPurple        
    navigationItem.rightBarButtonItem =  UIBarButtonItem(customView: sortButton)
    navigationItem.rightBarButtonItem?.tintColor = UIColor.myMusicPurple

推荐答案

如何使用:

func setTitleColor(UIColor?, for: UIControlState)

文档说它设置了用于指定状态的标题颜色.

Documentation says it sets the color of the title to use for the specified state.

sortButton.setTitleColor( .red, for: .normal)

这篇关于更改 UIBarButtonItem 的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆