iOS 给view添加虚线边框

2016.7.27

CAShapeLayer*border = [CAShapeLayerlayer];

border.strokeColor= [UIColorhexStringToColor:@"#cccccc"].CGColor;

border.fillColor=nil;

border.path= [UIBezierPathbezierPathWithRect:self.frontBtn.bounds].CGPath;

border.frame=self.frontBtn.bounds;

border.lineWidth=1.f;

border.lineCap=@"square";

border.lineDashPattern=@[@2,@2];//虚线的长和间距

[self.frontBtn.layeraddSublayer:border];

你可能感兴趣的:(iOS 给view添加虚线边框)