Reputation: 4946
I am having a problem setting the border colour on a UIView. If set tempColor
to [UIColor lighGreyColor], [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:1.0],
or [UIColor blueColor]
, the border gets set as expected. However, the code below does not set the colour and no border appears. unamecontainer
is UIView
. Any ideas why I can set the border colour to the colours mentioned above, and not the to the colour below.
UIColor *tempColor = [[UIColor alloc] initWithRed:169 green:201 blue:229 alpha:1.0];
self.unamecontainer.layer.borderColor = tempColor.CGColor;
self.unamecontainer.layer.borderWidth = 1.0;
Upvotes: 0
Views: 1152
Reputation: 9356
use this code
yourView.layer.borderColor = [UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:1.0f].CGColor;
view_buttons.layer.borderWidth = 1.0f;
Upvotes: 1
Reputation: 55334
The RGB values for UIColor
need to be in the range [0, 1]
, so you need to divide each value by 255.0
(not 255
because that is integer division) to get a percentage:
UIColor *tempColor = [[UIColor alloc]
initWithRed: 169/255.0
green: 201/255.0
blue: 229/255.0
alpha: 1.0];
Upvotes: 4
Reputation: 7703
red, green, and blue are floats from 0 to 1. Try
UIColor *tempColor = [[UIColor alloc] initWithRed:(169/255)f green:(201/255)f blue:(229/255)f alpha:1.0];
Upvotes: 0