Search code examples
iosobjective-cuicolor

Objective-C: Button's border colour is not getting displayed


I am trying to get the border on a button working for quite some time.

[self.accountButton.layer setBorderColor:(__bridge CGColorRef _Nullable)UIColorFromRGB( kGABrandingGreenColor )];

This is how the color's value is generated.

#define UIColorFromRGB(rgbValue) ([UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
                                              green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
                                               blue:((float)(rgbValue & 0xFF))/255.0 \
                                              alpha:1.0])

#define kGABrandingGreenColor       (0x53C2BE)

I haven't found a solution in stackoverflow which solves my issue.


Solution

  • it's easy

        #define UIColorFromRGB(rgbValue) \
    [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
    green:((float)((rgbValue & 0x00FF00) >>  8))/255.0 \
    blue:((float)((rgbValue & 0x0000FF) >>  0))/255.0 \
    alpha:1.0]
    
    #define kGABrandingGreenColor       (0xBC1128)
    
    
    [self.accountButton.layer setBorderWidth:3.0];
    [self.accountButton.layer setBorderColor:[UIColorFromRGB(kGABrandingGreenColor) CGColor]];