允许月份切换和日期选择的 SwiftUI 日历视图
可选择的日历视图
一个 SwiftUI 日历视图,允许月份切换和日期选择。
用法
您只需使用 Swift 包将此存储库添加到您的项目中,即可添加到您的 SwiftUI 视图代码中,然后使用以下代码显示日历:import SelectableCalendarView
import SelectableCalendarView
struct ContentView: View {
@State private var dateSelected: Date = Date()
var body: some View {
// monthToDisplay変数には、表示させたい月の任意の日を指定します。
SelectableCalendarView(monthToDisplay: Date(), dateSelected: $dateSelected)
}
}
You can also customize the colors of the calendar view, or to show/hide the month switching buttons by adjusting the .init parameters:
public struct SelectableCalendarView: View {
public init(monthToDisplay: Date, dateSelected: Binding<Date>, allowSwitchMonth: Bool = true, showMonthLabel: Bool = true, isDateCircleFilled: ((Date) -> Bool)? = nil) { ... }
}
monthToDisplay
is any day of the month you want to display.dateSelected
is the way your app reads/sets the date selected on the calendar view.allowSwitchMonth
controls whether the previous/next/current month switching buttons are shown.showMonthLabel
cnotrols whether the name of the month is shown or not.isDateCircleFilled
is a delegate-style function you use to indicate whether a date circle should be highlighted.
Install
Add a new Swift Package with the repository URL.
See here to learn how to add a package to your project.
The URL of this repository is: https://github.com/mszpro/Selectable-Calendar-View