How to customise UISlider height

后端 未结 9 1657
Happy的楠姐
Happy的楠姐 2020-12-06 05:42

I have project in which have to customise UISlider element. I wondering if someone knows how to change, or is it possible to change height of UISlide

9条回答
  •  借酒劲吻你
    2020-12-06 06:10

    Overriding trackRect is a way to go, however if you're using additional UISlider's views like minimumValueImage, maximumValueImage you would also need to take their bound into account, otherwise they will overlap with slider’s track. As a shortcut you can simply use super's func:

    Fixed version.

    Swift 3+

     @IBDesignable
        class CustomSlider: UISlider {
           /// custom slider track height
           @IBInspectable var trackHeight: CGFloat = 3
    
           override func trackRect(forBounds bounds: CGRect) -> CGRect {
               // Use properly calculated rect
               var newRect = super.trackRect(forBounds: bounds)
               newRect.size.height = trackHeight
               return newRect
           }
    }
    

提交回复
热议问题