Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView Border Color

I have the following code:

UIColor *borderColor = [UIColor colorWithRed:182 green:10 blue:96 alpha:1.0];
[viewImage.layer setBorderColor:borderColor.CGColor];
[viewImage.layer setBorderWidth:3.0];
[productView addSubview:viewImage];

where viewImage is my UIImageView and productView is my UIView.

I want to get this color enter image description here, but all I am getting is this color enter image description here. I tried different values, and all the colors that I am getting is either white, red, black, yellow, or blue. I can't get any other colors, doesn't matter what values I enter. I tried colorWithHue:Saturation:Brightness and I have the same issue.

I am using this on iOS 6 SDK.

What am I doing wrong and how can I fix it?

like image 405
BlueChips23 Avatar asked Oct 26 '12 01:10

BlueChips23


4 Answers

#import <QuartzCore/QuartzCore.h>

[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
like image 63
Bajaj Avatar answered Nov 18 '22 10:11

Bajaj


Try this

UIColor *color = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1];
like image 1
Son Nguyen Avatar answered Nov 18 '22 10:11

Son Nguyen


The values for red green and blue should be beween 0.0 and 1.0. From UIColor doc:

Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

like image 7
geraldWilliam Avatar answered Nov 18 '22 10:11

geraldWilliam


Swift version 2.11 (Xcode 7.2.1):

let borderColor = UIColor(red:0, green:0, blue:0, alpha:1.0)
viewImage.layer.borderColor = borderColor.CGColor
viewImage.layer.borderWidth = 2.0
like image 1
gone Avatar answered Nov 18 '22 08:11

gone