SWIFTUI I have a picker view(wheel type) and I clipped() its frame to half width of the screen, and from the UI you can see its half but the scrollable area is still actionable outside that frame. How can I remove that outer area to not be scrollable?
HStack(spacing: 0) {
Picker(selection: self.$viewModel.selectedFrameworkIndex, label: Text("")) {
ForEach(0 ..< viewModel.Categories.count) {
Text(self.viewModel.Categories[$0])
.foregroundColor((self.colorScheme == .dark) ? Color.white : Color.black)
}
}
.frame(width: width / 2) // width is width of my screen
.clipped()
}
SwiftUI’s ScrollView allows us to create scrolling containers of views relatively easily, because it automatically sizes itself to fit the content we place inside it and also automatically adds extra insets to avoid the safe area. Scroll views are vertical by default, but you can control the axis by passing in .horizontal as the first parameter.
Auto add to TabView with PageTabViewStyle style. You can control its appearance by .indexViewStyle. Integrate SwiftUI views into existing apps, and embed UIKit views and controllers into SwiftUI view hierarchies. Integrate SwiftUI views into existing apps, and embed UIKit views and controllers into SwiftUI view hierarchies.
Use this when you want to use UIViewController inside SwiftUI. To make any UIViewController usable in SwiftUI, create a wrapper view that conforms UIViewControllerRepresentable . Detail can be found in SwiftUI tutorials
You can control its appearance by .indexViewStyle. Integrate SwiftUI views into existing apps, and embed UIKit views and controllers into SwiftUI view hierarchies. Integrate SwiftUI views into existing apps, and embed UIKit views and controllers into SwiftUI view hierarchies.
Add .compositingGroup() after .clipped()
HStack(spacing: 0) {
Picker(selection: self.$viewModel.selectedFrameworkIndex, label: Text("")) {
ForEach(0 ..< viewModel.Categories.count) {
Text(self.viewModel.Categories[$0])
.foregroundColor((self.colorScheme == .dark) ? Color.white : Color.black)
}
}
.frame(width: width / 2) // width is width of my screen
.clipped()
.compositingGroup() }
Adding this extension
worked for me:
extension UIPickerView {
open override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: super.intrinsicContentSize.height)
}
}
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