Using a NSString to set a color for a label
问题 I want to create a method and use a string value "redColor" to set the UIColor for a label. tableColorName is the NSString "redColor" and I tried to apply a selector to create the UIColor and apply it to my textLabel. Thanks -(void) changeLabelColor { SEL labelColor = NSSelectorFromString([NSString stringWithFormat:[@"%@", tableColorName]]); UIColor *color = [[UIColor class] performSelector:labelColor]; self.textLabel.textColor = color; } 回答1: Use this method -(UIColor *