问题描述:

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

Thanks in advance!

网友答案:

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.

网友答案:

you can try this

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

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

网友答案:

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.

相关阅读:
Top