title: How to create a ruler / scale slider with Swift 3?
body: <p>I'm trying to recreate a temperature ruler similar to the Coinbase app for an app in Swift 3. Unfortunately, I'm not sure if I follow the right approach.</p>
  
  <p>In my current experiment, I used a UIScrollView element and placed / drawn lines at a certain distance (with a loop and UIBezierPath). In the next step I want to read the user input. With the current approach I have to use the X-position of the UIScrollView to convert things to read the current temperature. That seems to me a relatively inaccurate thing to be? My result looks like this.</p>
  
  <pre><code>// UI SCROLL VIEW
  var scrollView: UIScrollView!
  scrollView = UIScrollView(frame: CGRect(x: 0, y: 120, width: 400, height: 100))
  scrollView.contentSize = CGSize(width: 2000, height: 100)
  scrollView.showsHorizontalScrollIndicator = false
  
  let minTemp = 0.0
  let maxTemp = 36.8
  let interval = 0.1
  
  // LINES
  let lines = UIBezierPath()
  
  // DRAW TEMP OTHER LINES
  for temp in stride(from: minTemp, to: maxTemp, by: interval)
  {
      let isInteger = floor(temp) == temp
  
      let height = (isInteger) ? 20.0 : 10.0
      let oneLine = UIBezierPath()
      oneLine.move(to: CGPoint(x: temp*50, y: 0))
      oneLine.addLine(to: CGPoint(x: temp*50, y: height))
  
      lines.append(oneLine)
  
      // INDICATOR TEXT
      if(isInteger)
      {
          let label = UILabel(frame: CGRect(x: 0, y: 0, width: 40, height: 21))
          label.center = CGPoint(x: temp*50, y: height+15)
          label.font = UIFont(name: "HelveticaNeue",
                              size: 10.0)
          label.textAlignment = .center
          label.text = "\(temp) °C"
          scrollView.addSubview(label)
      }
  }
  
  // DESIGN LINES IN LAYER
  let shapeLayer = CAShapeLayer()
  shapeLayer.path = lines.cgPath
  shapeLayer.strokeColor = UIColor.black.cgColor
  shapeLayer.lineWidth = 1
  
  // ADD LINES IN LAYER
  scrollView.layer.addSublayer(shapeLayer)
  
  view.addSubview(scrollView)
  self.view = view
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xOvsF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xOvsF.png" alt="example result"></a></p>
  
  <p>The Coinbase app also struck me that there is some kind of adaptive feedback (at least on the iPhone X) when I move the slider. The iPhone vibrates easily when you come across a line, similar to the UIPickerView. I do not have that with my approach and I strongly doubt that the developer has programmed it in manually on Coinbase... So maybe there's a smarter, more up-to-date approach to how to recreate such a ruler natively in Swift?</p>
  
  <p><a href="https://i.stack.imgur.com/RgDkX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RgDkX.jpg" alt="Coinbase ruler example"></a></p>