首页 > 解决方案 > 如何更改输入的文本颜色?

问题描述

我正在制作一个脚本以允许用户更改元素颜色。

该脚本旨在处理按钮中的文本。

我试过这个:

func prettyText(_ button: RoundButton, colour: UIColor) {

   button.textColor = colour

}

但它给出了这个错误:

“RoundButton”类型的值没有成员“textColor”;您指的是 'tintColor' 吗?

标签: iosswift

解决方案


UIButtonsetTitleColor(_:for:)方法。所以在你的情况下

func prettyText(_ button: RoundButton, colour: UIColor) {
    button.setTitleColor(colour, for: .normal)
}

推荐阅读