0

enter image description hereI want to put two pickers in one line. And I used two guidelines (https://www.hackingwithswift.com/forums/swiftui/custom-multicomponent-picker-pure-swiftui/2236 and https://blckbirds.com/post/swiftui-how-to-create-a-multi-component-picker/)

my code:

import SwiftUI

struct Adding: View {
// my var’s
var body: some View {
        GeometryReader { geometry in
                Form{ 
                // my other code
                     () {
            Toggle(isOn: $time) {
                Text("Set a remind time")
            }
            if (time){
                HStack(spacing:0){
                    Picker("", selection: $minutes) {
                        ForEach(min, id: \.self) {
                            Text("\($0)").tag($0)
                        }
                    }.pickerStyle(WheelPickerStyle())
                        .labelsHidden()
                        .frame(width: geometry.size.width/2)
                        .clipped(antialiased: false)
                    Picker("", selection: $hours) {
                        ForEach(hr, id: \.self) {
                            Text("\($0)").tag($0)
                        }
                    }.pickerStyle(WheelPickerStyle())
                        .labelsHidden()
                        .frame(width: geometry.size.width/2)
                        .clipped()
                }
            }
            }
        }

But the active area doesn’t changes(like without .clipped() , but design changes)

What I’m doing wrong?

IDE: swift playgrounds (v. 4.1) Device: IPad (9-th gen) OS : IPadOS 15.5 (19F77)

  • Does this answer your question https://stackoverflow.com/a/72627822/12299030? – Asperi Jul 01 '22 at 18:40
  • Something like that, but it doesn’t working for me – Plutonictoast1 Jul 01 '22 at 18:59
  • Why not simply use a `DatePicker`? – Timmy Jul 01 '22 at 19:48
  • Thanks for advice :) But I’ll stay the question – Plutonictoast1 Jul 01 '22 at 20:35
  • Your code worked before. Apple must have changed something about clipped. In earlier os versions clipped did not just clip the design, but also the area you can touch. Unfortunately I don't have a solution for this problem, but I'm also looking for it, because DatePicker is not working for my case. – HeGe Sep 29 '22 at 07:48

1 Answers1

0

Use .compositingGroup() before .cliped()

.composititingGroup() modifier makes the following modifiers be applied to the view as a whole and not to each particular subview separately.

Apple doc compositingGroup()

Al Mustakim
  • 480
  • 4
  • 11