如何将nsstring转换为uicolor? [英] how to convert nsstring to uicolor?

查看:89
本文介绍了如何将nsstring转换为uicolor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在字符串中有一个字符串(NSString),有一个值像string = @black现在我想使用textcolore使用string.I已编写下面的代码。
txtView.textColor = [UIColor string];

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?

推荐答案

您可以使用 NSSelectorFromString 函数获取选择器,然后将其发送到UIColor。您还必须测试UIColor是否能够响应您必须避免错误的选择器:

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

这篇关于如何将nsstring转换为uicolor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆