5

I'm following some online examples I found on how to setup a UI Scroll View and have run into a problem with setting the size of the Scroll View. I'm attempting to set the size to height = height of screen and width = 3x width of screen. Here is the code I'm attempting, but CGSizeMake is no longer supported in Swift3. Any suggestions on how to accomplish this without CGSizeMake?

    self.scrollView.contentSize = CGSizeMake(self.view.frame.width * 2, self.view.frame.size.height)

Thanks!

Jay_Jordz
  • 75
  • 1
  • 8

1 Answers1

0

CGSizeMake is deprecated in Swift 3. Use regularCGSize instead. Your code should look like this:

self.scrollView.contentSize = CGSize(width: self.view.frame.width * 3, height: self.view.frame.height)

The main only difference between them is that you have to type in the parameter names (width, and height) for CGSize, while you do not need to for CGSizeMake.

You can take a look at this question for additional information: What's the difference between using CGSizeMake and CGSize? Is one better than the other?

Simply put, CGSize, is used more commonly in Swift because it's considered more "Swifty". CGSizeMake is a leftover from Objective-C

Community
  • 1
  • 1
Nik
  • 1,664
  • 2
  • 14
  • 27