Created
November 12, 2017 21:30
-
-
Save CodingMeSwiftly/83568f9b0b14b9c76b04425c6589e858 to your computer and use it in GitHub Desktop.
An extension on UIScrollView that adds vars to check if the scroll view can scroll.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIEdgeInsets { | |
var horizontalSum: CGFloat { | |
return left + right | |
} | |
var verticalSum: CGFloat { | |
return top + bottom | |
} | |
} | |
extension UIScrollView { | |
var canScrollVertically: Bool { | |
return contentSize.height + contentInset.verticalSum > frame.height | |
} | |
var canScrollHorizontally: Bool { | |
return contentSize.width + contentInset.horizontalSum > frame.width | |
} | |
var canScroll: Bool { | |
return canScrollHorizontally || canScrollVertically | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment