我有一個字符串(NSString)在字符串中有一個值像string = @「black」現在我想使用textcolore使用string.I寫下面的代碼。 txtView.textColor = [UIColor string];如何將nsstring轉換爲uicolor?
但它不工作可以建議我嗎?
我有一個字符串(NSString)在字符串中有一個值像string = @「black」現在我想使用textcolore使用string.I寫下面的代碼。 txtView.textColor = [UIColor string];如何將nsstring轉換爲uicolor?
但它不工作可以建議我嗎?
您可以使用NSSelectorFromString
函數獲得選擇器,然後將其發送給UIColor。您還必須測試,如果是的UIColor能夠爲你必須避免錯誤的選擇作出迴應:
SEL blackSel = NSSelectorFromString(@"blackColor");
UIColor* tColor = nil;
if ([UIColor respondsToSelector: blackSel])
tColor = [UIColor performSelector:blackSel];
這是我使用UIColor + Extensions h/m的完美選擇。我現在可以將此類別中的自定義UIColor名稱添加到我的plist數據中。 – malaki1974 2015-12-03 16:33:53
'txtView.textColor = [字符串的UIColor]'是完全錯誤的,告訴我們您更多的代碼。 – Pascal 2010-01-08 12:17:03