一个基于 SwiftUI 的自定义表单卡片,可在 iOS 应用程序中重复使用。
如果您想学习如何构建此类组件,请尝试以下教程。
将此 Swift 包添加到您的项目中
https://github.com/mahmudahsan/SwiftUI-Action-Sheet-Card
import SwiftUI
import ActionSheetCard
struct ContentView: View {
@State var showingSheet = false
var content: some View {
VStack {
Text("Custom Sheet")
.font(.largeTitle)
.padding()
Button(action: {
showingSheet = true
}) {
Text("Open Sheet")
}
}
.edgesIgnoringSafeArea(.all)
}
var sheetView: some View {
ActionSheetCard(isShowing: $showingSheet,
items: [
ActionSheetCardItem(sfSymbolName: "play", label: "Play") {
print("Play Tapped")
showingSheet = false
},
ActionSheetCardItem(sfSymbolName: "stop", label: "Stop", foregrounColor: Color.red) {
print("Stop Tapped")
showingSheet = false
},
ActionSheetCardItem(sfSymbolName: "record.circle", label: "Record")
])
}
var body: some View {
ZStack {
content
sheetView
}
}
}
import ActionSheetCard
@State var showingSheet = false
状态ActionSheetCard(isShowing: $showingSheet,
items: [
ActionSheetCardItem(sfSymbolName: "play", label: "Play") {
print("Play Tapped")
showingSheet = false
},
ActionSheetCardItem(sfSymbolName: "stop", label: "Stop", foregrounColor: Color.red) {
print("Stop Tapped")
showingSheet = false
},
ActionSheetCardItem(sfSymbolName: "record.circle", label: "Record")
])
ActionSheetCardItem(sfSymbolName: "stop", label: "Stop", foregrounColor: Color.red) {
// Callback
print("Stop Tapped")
showingSheet = false
}
// No Callback
ActionSheetCardItem(sfSymbolName: "record.circle", label: "Record")
ZStack
中使用表单,否则黑色背景视图将无法正确显示var body: some View {
ZStack {
content
sheetView
}
}
有关更多示例,请打开 /Demo/Demo.xcodeproj
// If font and color is not provide, default values will be used
ActionSheetCardItem(
label: "Stop",
sfSymbolName: "stop",
labelFont: Font.largeTitle,
foregrounColor: Color.red,
foregroundInactiveColor: Color.gray
) {
print("Stop Tapped")
showingSheet = false
},
ActionSheetCard(
isShowing: $showingSheet,
items: [],
backgroundColor: Color.red
)