Skip to content

Instantly share code, notes, and snippets.

@barisuyar
Created December 1, 2021 19:27
Show Gist options
  • Save barisuyar/45963a2db8ae1a0b81330f4fb18f27b3 to your computer and use it in GitHub Desktop.
Save barisuyar/45963a2db8ae1a0b81330f4fb18f27b3 to your computer and use it in GitHub Desktop.
Slider + Track positioning
private func setup() {
clear()
createBaseLayer() // Step 3
createThumbImageView() // Step 5
configureTrackLayer() // Step 7
addTarget(self, action: #selector(valueChanged(_:)), for: .valueChanged) // Step 8
}
// Step 8
@objc private func valueChanged(_ sender: Slider) {
let thumbRectA = thumbRect(forBounds: bounds,
trackRect: trackRect(forBounds: bounds),
value: value)
trackLayer.frame = .init(x: 0,
y: frame.height / 4,
width: thumbRectA.midX,
height: frame.height / 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment