要給
UIButton
等視圖加一圈虛線邊框,這裡是其中一種方法,就是在原來的視圖的
layer
上再添加一層
CAShapeLayer
,在這一層中使用貝塞爾曲線
UIBezierPath
的
lineDashPattern
建立虛線邊框。
UIView *view = [[UIView alloc] init];
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
layer.frame = CGRectMake(, , view.frame.size.width, view.frame.size.height);
layer.backgroundColor = [UIColor clearColor].CGColor;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:layer.frame cornerRadius:f];
layer.path = path.CGPath;
layer.lineWidth = f;
layer.lineDashPattern = @[@4, @4];
layer.fillColor = [UIColor clearColor].CGColor;
layer.strokeColor = [UIColor whiteColor].CGColor;
[view.layer addSublayer:layer];