How to get color components of a CGColor correctly

后端 未结 6 1177
日久生厌
日久生厌 2021-01-02 14:04

I have a UILabel with black color;

i am writing the following code to get black color\'s components.

UIColor *aColor = [aLabel.textColor retain];
con         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 14:24

    I think this is a very nice way to get the rgb representation of any UIColor*, which already has a convenience method for retaining it´s components.

    -(CGColorRef)CGColorRefFromUIColor:(UIColor*)newColor {
         CGFloat components[4] = {0.0,0.0,0.0,0.0};
         [newColor getRed:&components[0] green:&components[1] blue:&components[2]        alpha:&components[3]];
         CGColorRef newRGB = CGColorCreate(CGColorSpaceCreateDeviceRGB(), components);
         return newRGB;
    }
    

提交回复
热议问题