Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customise UISlider height

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 bar line.

I tried something like this but don't work:

let customBounds = CGRect(origin: bounds.origin, 
                          size: CGSize(width: bounds.size.width, height: 15.0))
feedbackSlider.trackRectForBounds(customBounds)

Thanks

like image 455
Nik Avatar asked Jul 23 '15 14:07

Nik


People also ask

How do I change the height of my UISlider?

If you're using autolayout you can set a height constraint on the UISlider in the storyboard . if you need to change it at runtime - create an IBOutlet for the constraint and modify its . constant value.


1 Answers

i hope that you want edit it in storyboard, and only the line size, use it in your custom UISlider

class CustomSlide: UISlider {

     @IBInspectable var trackHeight: CGFloat = 2

     override func trackRectForBounds(bounds: CGRect) -> CGRect {
         //set your bounds here
         return CGRect(origin: bounds.origin, size: CGSizeMake(bounds.width, trackHeight))



       }
}
like image 168
Learn Swift Avatar answered Oct 26 '22 10:10

Learn Swift