Making RGB color in Xcode

后端 未结 5 624
萌比男神i
萌比男神i 2020-12-02 07:06

I am using RGB values of a color from Photoshop and using the same in Xcode the values are.Color-R-160,G-97,B-5...the color in Photoshop appears yellowish but in Xcode when

5条回答
  •  旧巷少年郎
    2020-12-02 07:42

    You already got the right answer, but if you dislike the UIColor interface like me, you can do this:

    #import "UIColor+Helper.h"
    // ...
    myLabel.textColor = [UIColor colorWithRGBA:0xA06105FF];
    

    UIColor+Helper.h:

    #import 
    
    @interface UIColor (Helper)
    + (UIColor *)colorWithRGBA:(NSUInteger)color;
    @end
    

    UIColor+Helper.m:

    #import "UIColor+Helper.h"
    
    @implementation UIColor (Helper)
    
    + (UIColor *)colorWithRGBA:(NSUInteger)color
    {
        return [UIColor colorWithRed:((color >> 24) & 0xFF) / 255.0f
                               green:((color >> 16) & 0xFF) / 255.0f
                                blue:((color >> 8) & 0xFF) / 255.0f
                               alpha:((color) & 0xFF) / 255.0f];
    }
    
    @end
    

提交回复
热议问题