Abinodh Thomas
Abinodh Thomas

Reputation: 73

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.

Upvotes: 0

Views: 58

Answers (2)

user2877496
user2877496

Reputation: 233

You're close, just add the .CGColor to the define and remove the bridge. Also you need to set a borderWidth otherwise you won't see anything

#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]).CGColor

#define kGABrandingGreenColor       (0x53C2BE)


[self.accountButton.layer setBorderColor:UIColorFromRGB( kGABrandingGreenColor)];
self.accountButton.layer.borderWidth = 2.0f;

Upvotes: 0

Mohamed Helmy
Mohamed Helmy

Reputation: 832

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]];

Upvotes: 2

Related Questions