Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

How To Make a Custom Control Tutorial: A Reusable Slider

Controls are the bread-and-butter of iOS apps. There are many provided in UIKit but this tutorial shows you how to make a custom control in Swift.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2297-how-to-make-a-custom-control-tutorial-a-reusable-slider

I use XCode 7.3.1
I have to change the function application in AppDelegate.swift to:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
return true
}

hey, the addTarget method is not getting called!! what to do for using it

You mean the rangeSliderValueChanged selector isn’t being called?

Make sure to use the exact name of the method, or even better #selector syntax with a newer version of Swift.

Also make sure the method isn’t private for implicitly private, by for example being in a private extension. You might also try markig the method with dynamic, which works even if the method is private.

Same here: rangeSliderValueChanged is not called. I don’t know, maybe something broke while Xcode updated the project to the Swift 3.0. Also I had to silence some warnings manually, maybe this is the reason.

Seems like there is a bug with Swift 3 when using .valueChanged. It doesn’t get called, but if you change to some other event like .touchDown it will trigger it :confused: very wierd

I was trying to use this but when i drag it i have to issue

  1. First one is my rangeSliderValueChanged() Method is not getting called
  2. Second one is When i drag it it sucked after little bit dragging.

If you have some problems with the rangeSliderValueChanged() Method, try this:

rangeSlider.addTarget(self, action: #selector(ViewController.rangeSliderValueChanged), for: .valueChanged)

In my case it solved the problem.

For Swift 3…

Add the below single line code to the end of updateLayerFrames() function,

self.sendActions(for: .valueChanged)

and Pray for Apple God…God will surely help you.

Thanks so much for this tutorial!
Had to spend some time to adjust the code for XCode 9 and Swift 4 - but everything works perfectly now.
Extremely useful lesson

This tutorial is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]