标签:代码 nbsp swift override 旋转 graphics lin border stroke
1 override func draw(_ rect: CGRect) { 2 let context = UIGraphicsGetCurrentContext() 3 4 // MARK: - 注意:矩阵操作一定要在添加路径之前设置 5 6 // 旋转 - 逆时针旋转-M_PI_4(以原点为基准) 7 // context?.rotate(by: CGFloat(-M_PI_4)) 8 9 // 平移 - 往左下角(以原点为基准) 10 // context?.translateBy(x: 50, y: 50) 11 12 // 缩放 - 宽高各缩小一半(以原点为基准) 13 context?.scaleBy(x: 0.5, y: 0.5) 14 15 let borderPath = UIBezierPath(rect: rect) 16 17 let rectPath = UIBezierPath(rect: CGRect(x: 10, y: 10, width: 200, height: 200)) 18 19 let circlePath = UIBezierPath(ovalIn: CGRect(x: 10, y: 210, width: 200, height: 200)) 20 21 context?.addPath(borderPath.cgPath) 22 context?.addPath(rectPath.cgPath) 23 context?.addPath(circlePath.cgPath) 24 25 context?.setLineWidth(2) 26 27 context?.strokePath() 28 }
标签:代码 nbsp swift override 旋转 graphics lin border stroke
原文地址:http://www.cnblogs.com/panda1024/p/6256222.html