iOS-给View添加虚线
Quartz 2D绘制
- (void)addBorderToLayer2:(UIView*)view
{
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayersetBounds:view.bounds];
[shapeLayersetPosition:CGPointMake(CGRectGetWidth(view.frame) / 2, CGRectGetHeight(view.frame)/2)];
[shapeLayersetStrokeColor:[UIColor lightGrayColor].CGColor];
[shapeLayersetLineWidth:0.5];
//设置线宽,线间距
[shapeLayersetLineDashPattern:@[@6,@10]];
//设置路径
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
【iOS-给View添加虚线】if (CGRectGetWidth(view.frame) > CGRectGetHeight(view.frame)) {
CGPathAddLineToPoint(path, NULL, CGRectGetWidth(view.frame),0);
}else{
CGPathAddLineToPoint(path, NULL, 0,CGRectGetHeight(view.frame));
}
[shapeLayersetPath:path];
CGPathRelease(path);
//把绘制好的虚线添加上来
[view.layeraddSublayer:shapeLayer];
}
推荐阅读
- 喂,你结婚我给你随了个红包
- 成交的种子咖啡冥想
- 一百二十三夜,请嫁给我
- 每日一话(49)——一位清华教授在朋友圈给大学生的9条建议
- 历史教学书籍
- 写给陈羡
- 列出所有自定义的function和view
- 给予孩子心理平衡的机会
- 请给时间一点时间
- 写给我20岁时爱过的那个男孩