iOS Custom Slider remove min and max space from both ends

对着背影说爱祢 提交于 2019-12-31 05:41:11

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/52987375/ios-custom-slider-remove-min-and-max-space-from-both-ends

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