How do I create a UIColor from RGBA?

前端 未结 5 1562
迷失自我
迷失自我 2020-12-23 21:39

I want to use NSAttributedString in my project, but when I\'m trying to set color, which isn\'t from the standard set (redColor, blackColor

5条回答
  •  心在旅途
    2020-12-23 22:00

    UIColor uses a range from 0 to 1.0, not integers to 255.. Try this:

    // create color
    UIColor *color = [UIColor colorWithRed:66/255.0
                                     green:79/255.0
                                      blue:91/255.0
                                     alpha:1];
    
    // use in attributed string
    [attributedString addAttribute:NSForegroundColorAttributeName
                             value:color
                             range:NSMakeRange(0, attributedString.length)];
    

提交回复
热议问题