Search code examples
iosswiftuislidercgrectuicontrol

How to draw a static circle on a UISlider?


I'm trying to render a few small circles based on times of an event, I want it to look like this, the alert timings are defined before the view loads so it doesn't need to be dynamic but have no idea how to go about it, any advice / code would be great, thanks.

enter image description here


Solution

  • You have plenty of open source projects that cover your needs. Look at these links: http://www.brightec.co.uk/ideas/how-we-created-custom-slider-marks-ios http://www.raywenderlich.com/36288/how-to-make-a-custom-control http://www.alexanderbatalov.com/journal/2015/2/20/how-to-implement-custom-uislider-in-swift

    In connection to drawing circle you could simple use this code on UIView and after that add this to the slider

    func initializeCircle() {
        self.layer.cornerRadius = self.bounds.width/2
        self.layer.borderColor = UIColor.whiteColor().CGColor
        self.layer.borderWidth = 2.0
    }