Add border to image on iphone

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

Thanks in advance!

+4
source share
3 answers

If you are on iPhone OS 3.0, you can use the borderWidth and borderColor properties for your CALayer image to add a border above the image, as shown below:

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 border of 4 pixels wide with a fully opaque color having RGB values ​​halfway between white and black.

+6
source

you can try this

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

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

+6
source

I don’t think so, but you can put a gray UIView in place of your image and then add the image as a child of this gray UIView. Make the image a little smaller and center it, setting its frame accordingly, so that you see only a few pixels from the UIView behind. Thus, it will look as if the image has a border.

0
source

All Articles