WeekSchedule 是一个 SwiftUI 包,旨在帮助您轻松地在 iOS 和 macOS 应用程序中创建和管理每周日程。 无论您是构建日历应用程序、任务调度器还是时间管理工具,WeekSchedule
都提供了一种灵活且可定制的方式来显示每周时间线并与之交互。
生产应用程序中的使用示例
---WeekScheduleEntryView
。要使用 SwiftPM 将 WeekSchedule
集成到您的项目中,请将以下内容添加到您的 Package.swift
文件中。
dependencies: [
.package(url: "https://github.com/SaudAlhafith/WeekScheduleView", from: "0.3.0"),
],
或者直接在 Xcode 中添加
File
> Add Packages...
。https://github.com/SaudAlhafith/WeekScheduleView
。以下是如何创建一个简单的锻炼计划
import SwiftUI
import WeekSchedule
struct WorkoutScheduleView: View {
var sessions: [WorkoutSession] = [
// ...
]
var body: some View {
VStack {
WeekScheduleView(entries: sessions) { entry, day, options in
VStack(alignment: .leading, spacing: 4) {
VStack(alignment: .leading, spacing: 2) {
Text("\(day.name(style: .wide)) - \(entry.title)")
.font(.caption)
.bold()
if let subtitle = entry.subtitle {
Text(subtitle)
.font(.caption2)
.foregroundColor(.gray)
}
}
VStack {
Text(entry.startDate.formatted(.dateTime.hour().minute()))
.bold()
Text(entry.endDate.formatted(.dateTime.hour().minute()))
.bold()
}
.font(.system(size: 8))
.padding(.top, 2)
}
.padding(4)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(entry.color, lineWidth: 3)
)
.background(entry.color.opacity(0.3))
.cornerRadius(10)
}
.scheduleDays(.custom(days: [.monday, .tuesday, .wednesday]))
.timelineRange(.entriesOnly)
.timelineIndicator(.red) // New timeline indicator customization
.background(Color.gray.opacity(0.1), in: .rect(cornerRadius: 20))
.frame(height: UIScreen.main.bounds.height * 0.4)
Spacer()
}
}
}
您可以使用提供的修饰符来自定义日程
WeekScheduleView(entries: entries)
.scheduleDays(.fullWeek, daySpacing: 10, dayFont: .headline) // Show full week with spacing and font customization
.timelineRange(.fullDay) // Show 24-hour timeline
.timeline(.gray, font: .caption) // Customize timeline appearance
.timelineIndicator(.red) // Change timeline indicator color
.entryHeight(50, 100) // Set normal and expanded entry height
.isEntryExpanded(true) // Expand entries
.isEntryTimeShowing(true) // Show entry times
您可以使用 entryViewBuilder
闭包为日程条目提供自定义视图
WeekScheduleView(entries: entries) { entry, day, options in
HStack {
Text("\(day.name(style: .wide)) - \(entry.title)")
.font(options.dayFont)
Spacer()
Text(entry.subtitle)
.font(options.currentDayFont)
}
.padding()
.background(Color.green.opacity(0.2))
.cornerRadius(8)
}
WeekSchedule
完全支持从右到左 (RTL) 的语言。 只需设置环境的布局方向
WeekScheduleView(entries: entries)
.environment(\.layoutDirection, .rightToLeft)
main
分支。WeekSchedule
在 MIT 许可证下发布。 有关更多详细信息,请参见 LICENSE 文件。