How to convert NSString to UIColor

前端 未结 3 1710
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:20

    To convert from NSString to UIColor:

    NSString *redColorString = @"25";
    NSString *greenColorString = @"82";
    NSString *blueColorString = @"125";
    
    UIColor *color = [UIColor colorWithRed:[redColorString floatValue]/255.0
                                     green:[greenColorString floatValue]/255.0
                                      blue:[blueColorString floatValue]/255.0
                                     alpha:1.0];
    

提交回复
热议问题