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);
}
'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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With