实现思路还是较多的
1.创建一个view 给予旋转
2.贝塞尔曲线直接连线
今天就以第二张方式实现,
talk is cheap, show your code
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 40)];
label.backgroundColor = UIColor.systemGreenColor;
label.textAlignment = NSTextAlignmentCenter;
label.text = @"(¥98.00/年)";
[self.view addSubview:label];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 40)];
[path addLineToPoint:CGPointMake(100, 0)];
CAShapeLayer * shapeLayer = [CAShapeLayer layer];
shapeLayer.strokeColor = UIColor.systemRedColor.CGColor;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
/// 添加路径
shapeLayer.path = path.CGPath;
/// 线宽度
shapeLayer.lineWidth = 2;
[label.layer addSublayer:shapeLayer];
拓展:
写到view的category里面,
创建一个枚举,实现对角划线以及中间划线以及下划线几种样式
网友评论