抱歉,如果这是一个非常愚蠢的问题并且可能是题外话,但我似乎无法在任何地方找到它。
我正在尝试为我的应用程序做一个简单的设置部分,并希望将图标添加到我的元素中,以便用户可以轻松了解每个设置的作用。为了实现这一点,我使用HStack
了带有图像和标签 ( ) 的水平堆栈 ( Text
)。
这以某种方式起到了作用,但我想知道是否有更清洁的方法来做到这一点。我还想知道如何调整单元格之间的分隔符以停止在标签上,直到元素结束才继续。
由于我不太擅长解释,这里有两张图片:
我的代码:
SettingsView.swift
struct SettingsView: View {
@State var age: Int = 0
var body: some View {
UITableView.appearance().separatorStyle = .singleLine
UINavigationBar.appearance().shadowImage = UIImage()
return NavigationView {
Form {
Section {
Picker(selection: .constant(1), label: HStack {
Image(systemName: "paintbrush")
.font(Font.system(size: 25, weight: .light))
Text("Editor Theme")
}) {
Text("Ayu Mirage").tag(1)
Text("Ayu Light").tag(2)
}
Stepper(value: self.$age,
in: 18...100,
label: {
HStack {
Image(systemName: "rectangle.stack")
.font(Font.system(size: 25, weight: .light))
Text("Number of snippets: \(self.age)")
}
})
NavigationLink(destination: NotificationSettingsView()) {
HStack {
Image(systemName: "app.badge")
.font(Font.system(size: 25, weight: .light))
Text("Notifications")
}
}
}
Section {
VStack(alignment: .leading, spacing: 5) {
Text("Mercury v1.0")
.font(.headline)
Text("Designed with ❤️ by amodrono")
.font(.footnote)
}.padding(.vertical, 5)
}
}
.navigationBarTitle("Hello")
.environment(\.horizontalSizeClass, .regular)
.navigationBarTitle(Text("Settings"), displayMode: .inline)
.navigationBarItems(leading: (
Button(action: {
}) {
Image(systemName: "xmark")
.font(.headline)
.imageScale(.large)
.foregroundColor(Color(UIColor(named: "adaptiveColor")!))
}
))
}
}
}