Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

iphone - how to convert nsstring to uicolor?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...