I have implemented UISlider and I need to adjust track height. I found this but its not working.
self.slider.trackRect(forBounds: CGRect(x: 0, y: 0, width: 100, height: 100))
I have implemented UISlider and I need to adjust track height. I found this but its not working.
self.slider.trackRect(forBounds: CGRect(x: 0, y: 0, width: 100, height: 100))
found this but its not working
Because you're using it wrong. You don't call it. You subclass, and override it.
However, the right approach is to supply new images for the track, with setMinimumTrackImage
and setMaximumTrackImage
.
Ok...I used matt's answer + provided example and I customized the code for my needs.
let coinEnd = UIImage(/*HERE_LEFT_BLANK_IMG*/).resizableImage(withCapInsets:
UIEdgeInsetsMake(0,7,0,7), resizingMode: .stretch)
.
.
.
.
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var result = super.trackRect(forBounds: bounds)
result.origin.x = 0
result.size.width = bounds.size.width
result.size.height = 10 //added height for desired effect
return result
}
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
return super.thumbRect(forBounds:
bounds, trackRect: rect, value: value)
.offsetBy(dx: 0/*Set_0_value_to_center_thumb*/, dy: 0)
}
then inherid this to my Slider and woala.
This is my desired result.
All hail matt...thank you.
found this but its not working
Because you're using it wrong. You don't call it. You subclass, and override it.
However, the right approach is to supply new images for the track, with setMinimumTrackImage
and setMaximumTrackImage
.
© 2022 - 2024 — McMap. All rights reserved.