Skip to content

Instantly share code, notes, and snippets.

@ham118
Last active May 2, 2023 15:43
Show Gist options
  • Save ham118/2359f00d3d87cdaf655ca6cdae856d1d to your computer and use it in GitHub Desktop.
Save ham118/2359f00d3d87cdaf655ca6cdae856d1d to your computer and use it in GitHub Desktop.
To set customize UISlider height | Swift 4
//To set UISlider height, (which is by default not provided by UIKit framework)
//Steps:
//1. Add "CustomSlider" class in your swift file.
//2. Set "CustomSlider" class name into UISlider control from interface builder.
//3. Set "trackLineHeight" value as per requirment.
class CustomSlider: UISlider {
//Set line height value from Interface Builder,i.e. here ten is default value
@IBInspectable var trackLineHeight: CGFloat = 10
//Set custom size of track so here override trackRect function of slider control
override func trackRect(forBounds bound: CGRect) -> CGRect {
return CGRect(origin: bound.origin, size: CGSize(width: bound.width, height: trackLineHeight))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment