swiftuiscrollviewautolayoutscroller

Autolayout and storyboard not working - Swift?


I am new to swift and ios development and I have been following this tutorial: https://www.youtube.com/watch?v=Vq71SPkJIus

But for some reason even though I have the text in the feature view with autolayout to be centered it comes out all the way to the bottom

Screenshot: https://ibb.co/9p9XV4q

So far I have tried changing the constraints but that doesn't seem to move it up, its almost like something else is pushing it down?

@IBOutlet weak var pageControl: UIPageControl!
    @IBOutlet weak var slideScrollView: UIScrollView!
    override func viewDidLoad() {
        super.viewDidLoad()

        slideScrollView.delegate = self
        let slides:[Slide] = createSlides()
        setupScrollView(slides: slides)
        pageControl.numberOfPages = slides.count
        pageControl.currentPage = 0
        // Do any additional setup after loading the view, typically from a nib.
    }

    func createSlides() -> [Slide] {
        let slide1:Slide = Bundle.main.loadNibNamed("Slide", owner: self, options: nil)?.first as! Slide
        slide1.label.text = "Slide1"

        let slide2:Slide = Bundle.main.loadNibNamed("Slide", owner: self, options: nil)?.first as! Slide
        slide2.label.text = "Slide2"

        return [slide1, slide2]
    }

    func setupScrollView(slides:[Slide]) {
        slideScrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.width)
        slideScrollView.contentSize = CGSize(width: view.frame.width * CGFloat(slides.count), height: view.frame.height)
        slideScrollView.isPagingEnabled = true

        for i in 0 ..< slides.count {
            slides[i].frame = CGRect(x: view.frame.width * CGFloat(i), y: 0, width: view.frame.width, height: view.frame.height)
            slideScrollView.addSubview(slides[i])
        }
    }

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let pageIndex = round(scrollView.contentOffset.x/view.frame.width)
        pageControl.currentPage = Int(pageIndex)
    }

Solution

  • Wow realized that I am just dumb. Thanks to @vacawama for seeing that in setupScrollViewI put height: view.frame.width and not height: view.frame.height. That solved it thank you so much @vacawama