Reputation: 83
My problem is I need to change the label text color below my scroll view if the content of my scroll view is not all visible.
For example: I have a label colored red, if all the content of the scroll view can be seen on the screen(not using scroll at all), and the label colored blue if all the content inside of my scroll view is not visible. how to do it programmatically?
NOTE: I have a contentView -> scrollView (programmatically) -> stackView (programmatically). (stackview inside scrollview and scrollview inside contentview. and a label below the content view)
Thanks.
Upvotes: 2
Views: 3200
Reputation: 11
This solution worked for me, with the difference that I placed it in the viewDidAppear
if scrollView.contentSize.height > scrollView.visibleSize.height {
// can scroll more
} else {
// full content visible
}
Upvotes: 1
Reputation: 5225
1: Get the height of the content view of scrollView
let totalHeight = scrollView.contentSize.height
2: In viewDidLoad check:
if totalHeight > scrollView.frame.size.height {
// can scroll more
} else {
// full content visible
}
3: once user starts scrolling, you can call:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height)) {
//reached to bottom
} else {
// can scroll more
}
}
Upvotes: 3