2021-03-17 12:17:48 +08:00
|
|
|
//
|
|
|
|
// SawToothView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/3/17.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import UIKit
|
2021-07-06 19:32:11 +08:00
|
|
|
import Combine
|
2022-10-08 13:43:06 +08:00
|
|
|
import MastodonCore
|
2021-03-17 12:17:48 +08:00
|
|
|
|
2022-10-10 19:14:52 +08:00
|
|
|
public final class SawToothView: UIView {
|
2021-03-17 12:17:48 +08:00
|
|
|
static let widthUint = 8
|
|
|
|
|
2021-07-06 19:32:11 +08:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
2021-03-17 12:17:48 +08:00
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func _init() {
|
2023-09-27 15:08:12 +02:00
|
|
|
backgroundColor = .secondarySystemBackground
|
2021-03-17 12:17:48 +08:00
|
|
|
}
|
|
|
|
|
2022-10-10 19:14:52 +08:00
|
|
|
public override func draw(_ rect: CGRect) {
|
2021-03-17 12:17:48 +08:00
|
|
|
let bezierPath = UIBezierPath()
|
|
|
|
let bottomY = rect.height
|
|
|
|
let topY = 0
|
|
|
|
let count = Int(ceil(rect.width / CGFloat(SawToothView.widthUint)))
|
|
|
|
bezierPath.move(to: CGPoint(x: 0, y: bottomY))
|
|
|
|
for n in 0 ..< count {
|
|
|
|
bezierPath.addLine(to: CGPoint(x: CGFloat((Double(n) + 0.5) * Double(SawToothView.widthUint)), y: CGFloat(topY)))
|
|
|
|
bezierPath.addLine(to: CGPoint(x: CGFloat((Double(n) + 1) * Double(SawToothView.widthUint)), y: CGFloat(bottomY)))
|
|
|
|
}
|
|
|
|
bezierPath.addLine(to: CGPoint(x: 0, y: bottomY))
|
|
|
|
bezierPath.close()
|
2023-09-27 15:08:12 +02:00
|
|
|
SystemTheme.tableViewCellBackgroundColor.setFill()
|
2021-03-17 12:17:48 +08:00
|
|
|
bezierPath.fill()
|
|
|
|
bezierPath.lineWidth = 0
|
|
|
|
bezierPath.stroke()
|
|
|
|
}
|
2021-03-17 16:16:55 +08:00
|
|
|
|
2021-03-17 12:17:48 +08:00
|
|
|
}
|