UISlider track height

≡放荡痞女 提交于 2020-01-04 09:36:40

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/41959164/uislider-track-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!