有没有办法在SwiftUI中启用渐变按钮[+|-]?找不到关于这个主题的有用信息。
更新
我对@workingdogsupportUkraine的回答进行了一些外观上的调整。现在渐变按钮看起来与macOS 13上的设置应用程序类似。请随时提出任何改进建议。
import SwiftUI
struct TestView: View {
@State private var selection: Int?
struct GradientButton: View {
var glyph: String
var body: some View {
ZStack {
Image(systemName: glyph)
.fontWeight(.medium)
Color.clear
.frame(width: 24, height: 24)
}
}
}
var body: some View {
Form {
Section {
List(selection: $selection) {
ForEach(0 ..< 5) { Text("Item \($0)") }
}
.padding(.bottom, 24)
.overlay(alignment: .bottom, content: {
VStack(alignment: .leading, spacing: 0) {
Divider()
HStack(spacing: 0) {
Button(action: {}) {
GradientButton(glyph: "plus")
}
Divider().frame(height: 16)
Button(action: {}) {
GradientButton(glyph: "minus")
}
.disabled(selection == nil ? true : false)
}
.buttonStyle(.borderless)
}
.background(Rectangle().opacity(0.04))
})
}
}
.formStyle(.grouped)
}
}
Image()
中使用SF符号“加号”和“减号”。 - workingdog support Ukraine