class CMCoruseTicketRecordListView: UIView {
let winScale = ConstUtil.winScale
let fontScale = ConstUtil.fontScale
private(set) lazy var bgLayer : CAShapeLayer = {
let layer = CAShapeLayer()
layer.lineWidth = 3 * winScale
layer.strokeColor = UIColor.red.cgColor
layer.fillColor = UIColor.white.cgColor
return layer
}()
init() {
super.init(frame: .zero)
self.layer.insertSublayer(bgLayer, at: 0)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func draw(_ rect: CGRect) {
super.draw(rect)
setRadius(rect)
}
/// 设置圆角
private func setRadius(_ rect : CGRect){
let bigRadius = 15 * winScale
let smallRadius = bigRadius / 2.0
let bezierPath = UIBezierPath()
/// 左上
bezierPath.addArc(withCenter: CGPoint(x: bigRadius, y: bigRadius), radius: bigRadius, startAngle: CGFloat.pi, endAngle: CGFloat.pi * 3 / 2, clockwise: true)
/// 右上
bezierPath.addArc(withCenter: CGPoint(x: rect.width - bigRadius, y: bigRadius), radius: bigRadius, startAngle: -CGFloat.pi / 2, endAngle: 0, clockwise: true)
/// 右下
bezierPath.addArc(withCenter: CGPoint(x: rect.width - smallRadius, y: rect.height - smallRadius), radius: smallRadius, startAngle: 0, endAngle: CGFloat.pi / 2, clockwise: true)
/// 左下
bezierPath.addArc(withCenter: CGPoint(x: smallRadius, y: rect.height - smallRadius), radius: smallRadius, startAngle: CGFloat.pi / 2, endAngle: CGFloat.pi , clockwise: true)
bezierPath.addLine(to: CGPoint(x: 0, y: bigRadius))
bgLayer.path = bezierPath.cgPath
}
}
iOS 绘制不同半径的圆角
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- UIView的CALayer 一、首先简单的说下UIView的CALayer.UIView之所以能显示在屏幕上,完...
- UIBezierPath*path = [UIBezierPathbezierPath]; [pathmoveTo...