WeekSchedule

Latest release

contact: @SaudAlhafith

WeekSchedule 是一个 SwiftUI 包,旨在帮助您轻松地在 iOS 和 macOS 应用程序中创建和管理每周日程。 无论您是构建日历应用程序、任务调度器还是时间管理工具,WeekSchedule 都提供了一种灵活且可定制的方式来显示每周时间线并与之交互。

生产应用程序中的使用示例

WeekScheduleView

---

特性


要求


安装

Swift Package Manager

要使用 SwiftPM 将 WeekSchedule 集成到您的项目中,请将以下内容添加到您的 Package.swift 文件中。

dependencies: [
    .package(url: "https://github.com/SaudAlhafith/WeekScheduleView", from: "0.3.0"),
],

或者直接在 Xcode 中添加

  1. 转到 File > Add Packages...
  2. 输入存储库 URL:https://github.com/SaudAlhafith/WeekScheduleView
  3. 选择您要使用的版本。

用法

基本示例

以下是如何创建一个简单的锻炼计划

Workout Schedule View.

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)

交流


许可证

WeekSchedule 在 MIT 许可证下发布。 有关更多详细信息,请参见 LICENSE 文件。