Jay Taylor
Jay Taylor

Reputation: 51

Swift - Issues with setting background image in a UIScrollView

I have created a UIScrollView and added UILabels and UIButtons. I then have created a UIImageView and added it to the my UIScrollView. I have used the following code to set the UIImageView to the background of my UIScrollView.

        let paperImageView = UIImageView(image: UIImage(named: "White Notebook Paper.png"))
        paperImageView.frame = CGRect(x: -60, y: -60, width: UIScreen.main.bounds.width + 60, height: currentY + 60)
        scrollView.addSubview(paperImageView)
        scrollView.sendSubview(toBack: paperImageView)

As you can see in the following screenshot, by UIImageView is distorted.

enter image description here

The background image supposed to look like notebook paper. As you can see, the spacing of the lines becomes wider the lower you go in the UIScrollView. Thanks for taking the time to share your thoughts.

Upvotes: 0

Views: 685

Answers (1)

Jay Taylor
Jay Taylor

Reputation: 51

I forgot to change the content mode of the image view.

paperImageView.contentMode = .scaleAspectFill

Upvotes: 1

Related Questions