SwiftUI: ScrollView clipping
Problem
Some built-in view modifiers like .shadow
do not introduce any additional padding that would increase the intrinsic size of the view.
This can cause problems when views are placed within UIKit
hierarchies that enable .clipsToBounds
.
This is the case with ScrollView
, which internally uses a UIScrollView
.
Solution
>=
iOS 17
<
iOS 17
Extending UIScrollView
works, because .clipsToBounds
is not read-only.
import UIKit
extension UIScrollView {
open override var clipsToBounds: Bool {
get { false }
set { }
}
}
One should be aware that this is applied globally.
Attribution-NonCommercial 4.0 International
(only applies to text, code license: MIT)