Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGRectMake. Is Unavailable In Swift [duplicate]

Tags:

c#

xcode

swift

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)
like image 983
Michelle Avatar asked Apr 02 '18 04:04

Michelle


2 Answers

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).

like image 194
leedex Avatar answered Nov 17 '22 02:11

leedex


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)
like image 25
Vadlapalli Masthan Avatar answered Nov 17 '22 04:11

Vadlapalli Masthan