![](/img/trans.png)
[英]How to change height of a Picker with SegmentedPickerStyle() in SwiftUI?
[英]SwiftUI - Remove padding around Picker SegmentedPickerStyle when in a Form Section
我试图移除选择器周围的填充物,如下所示,我在来自 ObjectiveC 的 SwiftUI 仅几周。 下面是我设置填充和插图的各种尝试,任何帮助都会很棒
var body: some View {
Form {
Section {
Picker("", selection: $viewOption) {
Text("Staff").tag("staff")
Text("Signals").tag("signals")
}
.ignoresSafeArea()
.frame(height: 40)
.padding(EdgeInsets(top: -10, leading: 0, bottom: -10, trailing: 0))
.pickerStyle(SegmentedPickerStyle())
}.padding(EdgeInsets(top: 0, leading: -20, bottom: 0, trailing: -20))
.frame(height: 40)
.ignoresSafeArea()
Section(header: Text("YOUR PROFILE")) {
HStack {
Image(systemName: "person.circle")
.resizable()
.aspectRatio(contentMode: .fit)
//.clipShape(Circle())
.frame(width: 30, height: 30, alignment: .leading)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
VStack(alignment: .leading) {
Text("Andrew Webb").font(Font.system(size:20, design: .default))
Text("Test").font(.subheadline).fontWeight(.thin)
}
Spacer()
}
Toggle(isOn: $isOnDuty) {
Text("On Duty")
}.onChange(of: isOnDuty) { value in
self.isShowingModalAlert.toggle()
print(value)
}.sheet(isPresented: $isShowingModalAlert) {
ModalAlertSheetView(text: $alertInput, location: $location)
}
}
因为Form
使用分组列表样式,您必须将 inset 设置为零并更改选择器行的背景颜色:
Form {
Picker("My Picker", selection: .constant(0)) {
ForEach(0..<3) {
Text(String($0))
}
}
.pickerStyle(SegmentedPickerStyle())
.listRowInsets(.init())
.listRowBackground(Color(.secondarySystemBackground))
}
只需将其移到表单之外,例如
var body: some View {
VStack {
Picker {
}
Form {
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.