I’m making an attempt to make create a view which includes a button and a picker in a HStack to ultimately be positioned inside a type.
I would love the button to seamlessly mix with the sides of the listing row and I’ve been in a position to do that by utilizing the .listRowInsets() view modifier.
Nevertheless this removes the insets for the entire view. I might now like so as to add the insets again however solely to the picker and I would love this to be per all different listRows inside the shape, it doesn’t matter what the customers dynamic font is ready to.
Under is the view that created the Picker with the button, I’ve commented the place I believe the padding would wish to go.
struct PickerWithButton: View {
@Binding var choice: String
@Binding var strings: [String]
@Binding var toggle: Bool
var physique: some View {
HStack(spacing: 0){
Button(motion: { }, label: {
Picture(systemName: "plus")
})
.padding([.leading, .trailing], 12)
.body(maxHeight: .infinity, alignment: .heart)
.foregroundStyle(.white)
.background(.blue)
.onTapGesture {
toggle.toggle()
}
Picker("Picker", choice: $choice) {
ForEach(strings, id: .self){
Textual content($0)
}
}
.padding(.main, 20)
.padding([.top, .bottom], /*System Prime and Backside Record Row Insets*/ ) /*<---- Right here*/
}
.listRowInsets(EdgeInsets(high: 0, main: 0, backside: 0, trailing: 20))
//20 is what I believe the default is normally for this trailing edge
}
}
That is then positioned in a type like so
struct ContentView: View {
@State var string: String = "string"
@State var choices: [String] = ["string", "1", "2"]
@State var toggle: Bool = false
@State var userInput: String = ""
var physique: some View {
Kind{
PickerWithButton(choice: $string, strings: $choices, toggle: $toggle)
.alert("Alert Title", isPresented: $toggle){
TextField("Instance Textual content", textual content: $userInput)
Button("Add", position: .cancel) {
string = userInput
choices.append(userInput)
choices.kind()
userInput = ""
}
Button ("Cancel", position: .damaging) {
userInput = ""
}
}
}
}
}
At totally different font sizes the listRowInsets seem to increase and so hardcoding values in for the .padding implies that solely at the usual dimension does this view look like per the opposite objects within the type.
How might I calculate or be advised by the system what the listRowInsets are or does anybody know one other manner of dealing with this concern?
I’ve tried googling find out how to use EdgeInsets and I’ve tried utilizing Geometry Reader however to no avail.
Thank You
For transparency I’ve additionally posted this on Reddit