iOS Custom Slider remove min and max space from bo

2020-05-08 17:29发布

I'm trying to make custom slider using

class MySlider: UISlider {

    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        let customBounds = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width, height: 5.0))
        super.trackRect(forBounds: customBounds)
        return customBounds
    }
}

Updated thumb/max/min tint colour from storyboard enter image description here

The problem is need to remove min and max space from both ends as shown in pics. How i can do that? enter image description here enter image description here

1条回答
萌系小妹纸
2楼-- · 2020-05-08 18:06

I was able to achieve this without subclassing:

Set Thumb Tint: Default through IB

@IBOutlet weak var slider: MySlider!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let size = CGSize(width: 1 , height: 1)
        UIGraphicsBeginImageContext(size)
        let finalImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        slider.setThumbImage(finalImage, for: .normal)
    }
查看更多
登录 后发表回答