xcode 7.0
developTarget 9.0
代碼:
- (void)createDotBorderForView:(UIView *)view
{
view.layer.cornerRadius = f;
CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = [UIColor orangeColor].CGColor;
border.cornerRadius = f;
border.fillColor = nil;
border.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds cornerRadius:].CGPath;
border.frame = view.bounds;
border.lineWidth = f;
border.lineCap = kCALineCapRound;
border.lineDashPattern = @[@5, @3];// @5是虛線長度 @3是間距的長度
[view.layer addSublayer:border];
}
傳入你想要加虛線的View。