gpt4 book ai didi

ios - 在选择上快速更改文本颜色

转载 作者:可可西里 更新时间:2023-10-31 23:54:52 24 4
gpt4 key购买 nike

如何在 iOS Swift 中更改 labelcelltextColor 选择?

我希望背景不要改变。只有 textColorseperatorColor(如果有)。像这样的东西:

label.highlightedTextColor = UIColor.whiteColor();

我已经在一些应用程序中看到这种情况发生,颜色会发生变化。但我无法靠近它。根据 Apple Dev 引用:

Subclasses that use labels to implement a type of text button can use the value in this property when drawing the pressed state for the button. This color is applied to the label automatically whenever the highlighted property is set to true.

但是,标签可以很好地编译并且不会在突出显示时改变颜色。按钮没有 highlightedTextColor

最佳答案

我已经尝试在 didSelectAtIndexPathdidDeselectAtIndexPath 中设置它,但颜色会随着延迟而改变。我不喜欢那样。

这就是我最终解决问题的方式:

我已将我的 UITableViewCell 子类化并连接所有 @IBOutlet。在 awakeFromNib() 中,我只是这样做了:

@IBOutlet weak var myLabel: UILabel!


override func awakeFromNib() {
super.awakeFromNib()

self.myLabel.highlightedTextColor = .blackColor()

}

现在完美运行!

顺便说一句,这是我关于堆栈溢出的第一个答案,请对我好点😊呵呵

(我使用的是 Swift 2.0 和 Xcode 7.2.1)

关于ios - 在选择上快速更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27938906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com