How to disable vertical scrolling UIScrollView?
<h2>Problem</h2>

<p><a href="http://im2.ezgif.com/tmp/ezgif-2269702568.gif" rel="nofollow noreferrer">http://im2.ezgif.com/tmp/ezgif-2269702568.gif</a></p>

<p>I've set the <code>contentSize</code> to the height that I want. However,  my scrollview still has vertical scrolling. In fact there's lots of empty white space, which I'm not sure why. </p>

<p>And I'm not sure if it's because I do:        <code>contentOffset = CGPoint(x:0, y: self.frame.minY)</code>. But the reason I did that was because when I placed my buttons in the scroll view, I would have to scroll down to see them. <code>contentOffset</code> allows the buttons to be on the scrollview when it is loaded.</p>

<p>If someone could disable the vertical scrolling while still having the buttons show up that would be great!</p>

<h2>Code</h2>

<p>In my view controller I set up the custom scrollview:</p>

<pre><code>class ScheduleViewController: UIViewController {
    private var scheduleBar: ScheduleBar!
    private let barHeight: CGFloat = 55
    override func viewDidLoad() {
        super.viewDidLoad()
        scheduleBar = ScheduleBar(frame: CGRect(x: 0, y: (self.navigationController?.navigationBar.frame.maxY)!, width: self.view.bounds.width, height: barHeight))
        scheduleBar.setUp(buttonsData: times, selected: 2)
        self.view.addSubview(scheduleBar)
   }
}
</code></pre>

<p>In the custom scrollview I set up my scrollview further:</p>

<pre><code>class ScheduleBar: UIScrollView {
    private var buttons: [UIButton]!
    private var bar: UIView!
    private var buttonWidth: CGFloat!
    private var buttonPadding: CGFloat = 20

func setUp(buttonsData: [String], selected: Int){
        self.backgroundColor = UIColor.white

        buttons = []
        for time in buttonsData{
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: self.bounds.height))
            button.setTitle(time, for: UIControlState.normal)
            button.setTitleColor(Color.black, for: UIControlState.normal)
            button.titleLabel?.font = UIFont(name: "HelveticaNeue-Medium", size: 13.0)
            button.sizeToFit()
            buttonWidth = button.bounds.width + buttonPadding
            buttons.append(button)
        }
        for i in 0...(buttons.count-1){
            if i == 0 {
                buttons[i].frame = buttons[i].frame.offsetBy(dx:buttonPadding/2, dy: 0)
            }else if i == buttons.count-1{
               buttons[i].frame = buttons[i].frame.offsetBy(dx: CGFloat(i) * buttonWidth + buttonPadding/2, dy: 0)
            }
            else{
              buttons[i].frame = buttons[i].frame.offsetBy(dx: CGFloat(i) * buttonWidth + buttonPadding, dy: 0)
            }
            buttons[i].center.y = (self.bounds.height/2)
            addSubview(buttons[i])
        }

        bar = UIView(frame: CGRect(x: 0, y: self.bounds.height - 3.0, width: buttons[0].bounds.width + buttonPadding, height: 3.0))
        bar.backgroundColor = Color.red
        select(index: selected, animation: false)
        addSubview(bar)

        self.contentSize = CGSize(width: CGFloat(buttons.count) * buttonWidth + buttonPadding, height: self.bounds.height)
        //reset origin of scrollview
        self.contentOffset = CGPoint(x:0, y: self.frame.minY)
    }

    func select(index: Int, animation: Bool){
        func select() -&gt; Void{
            if index == 0{
                bar.frame.origin.x = CGFloat(0)
            }else{
                bar.frame.origin.x = buttons[index].frame.minX - buttonPadding/2
            }
        }
        if animation {
            UIView.animate(withDuration: 0.7, animations: {select()})
        }else{
            select()
        }
        scrollRectToVisible(CGRect(x: buttons[index].frame.minX, y: self.frame.minY, width: buttons[index].bounds.width, height: buttons[index].bounds.height), animated: true)
    }
</code></pre>