How to I properly set UIColor from int?

后端 未结 6 891
余生分开走
余生分开走 2021-01-05 11:47

I am trying to set the textColor of a UITextView by assigning it a value.

Earlier in the program I have

textView.textColor         


        
6条回答
  •  旧时难觅i
    2021-01-05 12:14

    it was necessary to use

    textView.textColor = [UIColor colorWithRed:<#(CGFloat)#> green:<#(CGFloat)#> blue:<#(CGFloat)#> alpha:<#(CGFloat)#>];
    

    try it:

    - (UIColor *)UIColorFromRGB:(NSInteger)rgbValue {
        return [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0
                               green:((float)((rgbValue & 0xFF00) >> 8))/255.0
                                blue:((float)(rgbValue & 0xFF))/255.0
                               alpha:1.0];
    }
    

    ...

    textView.textColor = [self UIColorFromRGB:0x888888];
    

提交回复
热议问题