How to convert NSString to UIColor

前端 未结 3 1679
Happy的楠姐
Happy的楠姐 2021-01-14 11:35

I have a pickerView which has a component of colors.

I have a textField (textOther), now I have NSMutableArray of all the available colors which are explicitly defin

3条回答
  •  心在旅途
    2021-01-14 12:16

    It´s better to create a method to convert for NSString to UIColor. You shoud have a NSString with for example whiteColor or blueColor and you can convert it in the following way:

      -(UIColor *)getColor:(NSString*)col
    
      {
    
      SEL selColor = NSSelectorFromString(col);
      UIColor *color = nil;
      if ( [UIColor respondsToSelector:selColor] == YES) {
    
        color = [UIColor performSelector:selColor];
       }  
        return color;
      }
    

提交回复
热议问题