Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISlider track height

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

enter image description here

like image 866
Pan Mluvčí Avatar asked Dec 15 '22 01:12

Pan Mluvčí


1 Answers

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.

enter image description here

This is my desired result.

enter image description here

All hail matt...thank you.

like image 98
Pan Mluvčí Avatar answered Mar 03 '23 01:03

Pan Mluvčí