Skip to content

Instantly share code, notes, and snippets.

@barisuyar
Created December 1, 2021 18:52
Show Gist options
  • Save barisuyar/b2ff26c8d222c32bdcf946e5c10e53d5 to your computer and use it in GitHub Desktop.
Save barisuyar/b2ff26c8d222c32bdcf946e5c10e53d5 to your computer and use it in GitHub Desktop.
Slider-3
final class Slider: UISlider {
private let baseLayer = CALayer() // Step 3
override func draw(_ rect: CGRect) {
super.draw(rect)
setup()
}
private func setup() {
clear()
createBaseLayer() // Step 3
}
private func clear() {
tintColor = .clear
maximumTrackTintColor = .clear
backgroundColor = .clear
thumbTintColor = .clear
}
// Step 3
private func createBaseLayer() {
baseLayer.borderWidth = 1
baseLayer.borderColor = UIColor.lightGray.cgColor
baseLayer.masksToBounds = true
baseLayer.backgroundColor = UIColor.white.cgColor
baseLayer.frame = .init(x: 0,
y: frame.height / 4,
width: frame.width,
height: frame.height / 2)
baseLayer.cornerRadius = baseLayer.frame.height / 2
layer.insertSublayer(baseLayer, at: 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment