Alex Rivera | Logout

how to convert nsstring to uicolor?

Asked 2010-01-08T11:34:53.717
9

I have one string(NSString) in string there is one value like string=@"black" now i want to use textcolore using string.I have written below code. txtView.textColor=[UIColor string];

But it not working can suggest me?

Edit
Report

1 Answer

23

You can get selector using NSSelectorFromString function and then send it to UIColor. You must also test if UIColor is able to respond to the selector you have to avoid error:

SEL blackSel = NSSelectorFromString(@"blackColor");
UIColor* tColor = nil;
if ([UIColor respondsToSelector: blackSel])
      tColor  = [UIColor performSelector:blackSel];
answered 2010-01-08T11:50:19.423

Your Answer