iosswiftios8ios8.1

Swift Change textColor on Selection


How do I change the textColor of a label or a cell on selection in iOS Swift?

I want the background to not to change. Only textColor and seperatorColor if any. Something like:

label.highlightedTextColor = UIColor.whiteColor();

I have seen this happen in some apps that the color changes. But I cannot get any near to it. According to Apple Dev Reference:

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.

But, labels compile fine and don't change color on highlight. Buttons do not have highlightedTextColor


Solution

  • if you (use/not use) a custom cell(as xib), you can select the lable, and from utilities, go to highlighted and change the color to the color you want to show in selection. and this is a snapshot to be more clear :) snapshot