I have looked on SO but cannot find an answer that works for me, so here goes:
I am trying to set color, font and size elements based on user preferences. I have no problem with font and font size, but I cannot seem to get the color to work.
This is what I’m doing:
-
I have a group of constants, like:
asterisk define kBlackColor @”[UIColor blackColor]”
-
In reading my prefs file, I’ve determined that I want the blackColor, and set
txtColor = kBlackColor;
txtColor is defined as:
NSString *txtColor;
-
When I want to use txtColor, I’m writing this:
cell.textLabel.textColor = (UIColor *) txtColor;
This compiles, but gives me an “unrecognized selector sent” message.
I would appreciate knowing the right way to go about this..
I decided to come at the problem a different way, so I should answer my own question – I hope it helps someone.
Instead of allowing users to change each setting, I created a series of styles (0-5), stored (among other things) in a plist.
Each style has a set of variables (font name, size, color, etc).
The settings file uses variables as shown below and is read when the app is started:
selectedTintColor and selectedFontColor are defined as:
fontName and backgroundImage are defined as NSStrings. font size is a local integer.
When I want to style a cell, I only have to enter this:
(The tintColor is used to style segmentedCells.)
Again, I hope this helps someone. It took me all night to get to this rather simple solution..