Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel text color is not changing programmatically, if I set the text color in nib and define that color in assets

The issues is cause by setting a custom color in the storyboard,its not related to custom font.

Step 1: Define color in Assets Folder

enter image description here

Step 2: Set that color as label text color

enter image description here

Step 3: Change the text color in code

enter image description here

Label background color is changing but text color is not changing

like image 599
Imran Avatar asked Sep 16 '18 14:09

Imran


People also ask

How do I change the color of my UILabel Swift?

The easiest workaround is create dummy labels in IB, give them the text the color you like and set to hidden. You can then reference this color in your code to set your label to the desired color. The only way I could change the text color programmatically was by using the standard colors, UIColor.


1 Answers

I faced the exact same problem. I suppose it's a bug in the xCode. The issue arrises when you set custom colour in storyboard or xib. What you can do:

  1. Use some standard colour in your nib file/storyboard
  2. If you want to change it with some colour asset this can be done programmatically at any time

I tried it and it works.

like image 125
Sophie Avatar answered Oct 11 '22 23:10

Sophie