17

can someone help me here I am currently getting this error saying that CGRectMake is not available in Swift. I have looked at other answers on this and I am still getting a little confused. Could anyone please write me an exact answer would be much appreciated.

 scrollView.frame = CGRect(0, 0, self.view.frame.width, self.view.frame.height)
technerd
  • 14,144
  • 10
  • 61
  • 92
Michelle
  • 195
  • 1
  • 1
  • 3

2 Answers2

42

CGRectMake has been deprecated. The syntax is now just CGRect. I believe the syntax change was introduced in Swift 3.

Notice that the x and y together form a CGPoint, and the width and height form a CGSize. So when you say:

scrollView.frame = CGRect(0, 0, self.view.frame.width, self.view.frame.height)

you are putting the scrollView at the CGPoint (0,0) and giving it the same same CGSize as the width and height of the view (covering the whole view).

leedex
  • 963
  • 8
  • 19
  • 1
    using like this: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height) – Namo Oct 03 '20 at 05:27
7

Which Swift version are you using? I think you are using Swift 3 and above.

CGRectMake is deprecated after Swift 3. You have to use CGRect instead of CGRectMake.

     let scrollView = UIScrollView()

     scrollView.frame = CGRect(0,0,self.view.frame.width,self.view.frame.height)
Bart
  • 2,606
  • 21
  • 32
  • I am using the latest swift 3 and thank you for your answers I am trying these today and I will let you now what worked for me much appreciated. – Michelle Apr 02 '18 at 22:55