Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'CGRectGetWidth' has been replaced by property 'CGRect.width' [duplicate]

Tags:

swift

swift4

I'm trying to Test the offset and calculate the current page after scrolling ends.

I just need to update this line to swift 4 ?

let pageWidth: CGFloat = CGRectGetWidth(scrollView.frame)

'CGRectGetWidth' has been replaced by property 'CGRect.width'

  //MARK: UIScrollViewDelegate
    override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){
       let pageWidth: CGFloat = CGRectGetWidth(scrollView.frame)
        let currentPage:CGFloat = floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1
        // Change the indicator
        pageControl.currentPage = Int(currentPage);

    }
like image 782
Faris Avatar asked May 23 '18 09:05

Faris


1 Answers

'CGRectGetWidth' has been replaced by property 'CGRect.width'

scrollView.frame returns a CGRect. so you can use the width property of the CGRect

Like so:

scrollView.frame.width

This is a simple issue to solve, you should always refer to the documentation first when you are not sure. Here you are trying to get the width of a CGRect, so check the CGRect documentation and see if it has a way to access the size/width.

like image 123
Scriptable Avatar answered Nov 10 '22 17:11

Scriptable