button 添加虚线外框

CAShapeLayer*border = [CAShapeLayerlayer];//虚线的颜色

border.strokeColor = [UIColorredColor].CGColor;//填充的颜色

border.fillColor = [UIColorclearColor].CGColor;

UIBezierPath*path = [UIBezierPathbezierPathWithRoundedRect:self.lineButton.bounds cornerRadius:5];

//设置路径border.path = path.CGPath; 

 border.frame =self.lineButton.bounds;

//虚线的宽度

border.lineWidth =1.f;

//设置线条的样式

// border.lineCap = @"square";

//虚线的间隔border.lineDashPattern = @[@4, @2];

self.lineButton.layer.cornerRadius =5.f;

self.lineButton.layer.masksToBounds =YES; 

 [self.lineButton.layer addSublayer:border];

你可能感兴趣的:(button 添加虚线外框)