Iya
Iya

Reputation: 67

Add border to a image in iphone

I have an image in a custom cell. Is there any api to add a gray border to an image?

Thanks in advance!

Upvotes: 4

Views: 11796

Answers (3)

Deepak
Deepak

Reputation: 437

you can try this

[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];

for this you need import <QuartzCore/QuartzCore.h>

Upvotes: 6

Brad Larson
Brad Larson

Reputation: 170309

If you are on iPhone OS 3.0, you can use the borderWidth and borderColor properties of your image view's CALayer to add a border over the image, as follows:

imageView.layer.borderWidth = 4.0f;
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGFloat values[4] = {0.5, 0.5, 0.5, 1.0}; 
CGColorRef grey = CGColorCreate(space, values); 
imageView.layer.borderColor = grey;
CGColorRelease(grey);
CGColorSpaceRelease(space);

This creates a 4-pixel-wide border with a fully opaque color having RGB values midway between white and black.

Upvotes: 6

luvieere
luvieere

Reputation: 37494

I don't think so, but you can put a gray UIView instead of your image, and then add the image as child of this gray UIView. Make the image a little smaller, and put it in the center, by setting its frame appropriately, so that you'll only see a few pixels from the UIView behind. This way, it will appear as if the image has a border.

Upvotes: 0

Related Questions