一般设置内边框:
self.headImg.layer.borderColor = [UIColor redColor].CGColor;
self.headImg.layer.borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
而设置外边框:(注意:backView 是headImg的父视图,这个layer是沿着headImg边框路径,添加到backView的layer)
CGFloat borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(self.headImg.frame.origin.x - borderWidth, self.headImg.frame.origin.y - borderWidth, self.headImg.frame.size.width + 2 * borderWidth, self.headImg.frame.size.height + 2 * borderWidth);
layer.masksToBounds = YES;
layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*(50 + 2 * borderWidth)/2;
// layer.borderColor = RGBA(255, 196, 15, 0.3).CGColor;
layer.borderColor = [UIColor redColor].CGColor;
layer.borderWidth = [UIScreen mainScreen].bounds.size.width/375*2;
[self.backView.layer addSublayer:layer];
网友评论