创建一个高度为1的虚线
程序员文章站
2023-12-24 19:08:39
...
///创建一个高为1的线
func config() {
let lineView = UIView(frame: CGRect(x: 2, y: 300, width: self.view.frame.size.width - 4, height: 1))
self.view.addSubview(lineView)
drawDashLine(lineView: lineView, lineLength: 10, lineSpacing: 5, lineColor: UIColor.red)
}
/**
* 通过 CAShapeLayer 方式绘制虚线
* lineView: 需要绘制成虚线的view
* lineLength: 线宽
* lineSpacing: 线间距
**/
func drawDashLine(lineView : UIView, lineLength : Int ,lineSpacing : Int,lineColor : UIColor){
let shapeLayer = CAShapeLayer()
shapeLayer.bounds = lineView.bounds
//只要是CALayer这种类型,他的anchorPoint默认都是(0.5,0.5)
shapeLayer.anchorPoint = CGPoint(x: 0, y: 0)
//shapeLayer.fillColor = UIColor.blue.cgColor
shapeLayer.strokeColor = lineColor.cgColor
shapeLayer.lineWidth = lineView.frame.size.height
shapeLayer.lineJoin = kCALineJoinRound
shapeLayer.lineDashPattern = [NSNumber(value: lineLength),NSNumber(value: lineSpacing)]
let path = CGMutablePath()
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: lineView.frame.size.width, y: 0))
shapeLayer.path = path
lineView.layer.addSublayer(shapeLayer)
}
推荐阅读
-
创建一个高度为1的虚线
-
Linux上为你的任务创建一个自定义的系统托盘指示器
-
编写一个表示二维平面上的点的类MyPoint,满足以下条件: 1、定义private的成员变量x和y,表示点的x和y坐标,类型为double
-
在程序大奖赛中,有10个评委为参赛的选手打分,分数为1~100分。选手最后得分为:去掉一个最高分和一个最低分后其余8个分数的平均值。
-
LeetCode 1 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
-
c语言将一个数组中的值按逆序重新存放。例如,原来顺序为8,6,5,4,1.要求改为1,4,5,6,8.
-
Java经典编程习题100例:第18例:编写程序,将一个数组中的元素倒排过来。例如原数组为1,2,3,4,5;则倒排后数组中的值
-
java-66-用递归颠倒一个栈。例如输入栈{1,2,3,4,5},1在栈顶。颠倒之后的栈为{5,4,3,2,1},5处在栈顶...
-
将一个数组中的值按逆序重新存放,例如,原来顺序为8,6,5,4,1.要求改为1,4,5,6,8。
-
5.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1