iOS:虚线边框

#pragma mark - 控件虚线边框
/**
 给控件设置虚线边框

 @param strokeColor 边框颜色
 @param fillColor 控件填充颜色
 @param rect 控件的bound
 @param width 虚线的宽度
 @param pattern 虚线的间隔:数组
 @param radius 控件的圆角
 @return layer
 */
-(CAShapeLayer *)newLayer:(UIColor *)strokeColor fillColor:(UIColor *)fillColor rect:(CGRect)rect width:(CGFloat)width pattern:(NSArray *)pattern radius:(CGFloat)radius{
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.strokeColor = strokeColor.CGColor;
    layer.fillColor = fillColor.CGColor;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
    layer.path = path.CGPath;
    layer.frame = rect;
    layer.lineWidth = width;
    layer.lineDashPattern = pattern;
    layer.masksToBounds = YES;
    return layer;
}

调用

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(16, 0, self.view.frame.size.width - 32, 45);
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:17];
    btn.layer.masksToBounds = YES;
    [self.view addSubview:btn];
    [btn.layer addSublayer:[self newLayer:theme_Color fillColor:[UIColor clearColor] rect:btn.bounds width:1.0 pattern:@[@(2)] radius:5]];
上一篇:微信卡片流图片懒加载(监听所有图片)


下一篇:C#表达式体方法 (expression-bodied method ) - 0023