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...