(原)带圆角矩形边框的view

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
CGFloat col[] = {1, 1, 1, 1}; //背景色.
float offset = XXX_EdgeWidth;//边宽
self.backgroundColor = XXX_EdgeColor;//边框色.

//圆角
self.layer.cornerRadius = 8.0f;
self.layer.masksToBounds = YES;

//弄出一个圆角的边
CGRect frame2 = frame;
frame2.origin.x = offset;
frame2.origin.y = offset;
frame2.size.width -= offset * 2;
frame2.size.height -= offset * 2;
CALayer *layer2 = [[CALayer alloc] init];
layer2.frame = frame2;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRelease(layer2.backgroundColor = CGColorCreate(colorSpace, col));
CGColorSpaceRelease(colorSpace);
layer2.cornerRadius = self.layer.cornerRadius - offset;
self.layer.masksToBounds = YES;
[self.layer addSublayer:layer2];
[layer2 release];
}
return self;
}
posted @ 2012-02-28 12:02  小鼬就是我  阅读(572)  评论(0编辑  收藏  举报