Skip to content

Instantly share code, notes, and snippets.

@CodingMeSwiftly
Created November 12, 2017 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodingMeSwiftly/83568f9b0b14b9c76b04425c6589e858 to your computer and use it in GitHub Desktop.
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.
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