You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-6Lines changed: 69 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,16 @@ Documentation is automatically generated from source code comments and rendered
17
17
Usage
18
18
----------
19
19
20
+
### `YCalendarPicker` (UIKit)
21
+
`YCalendarPicker` is a subclass of `UIControl` with an api similar to `UIDatePicker`.
22
+
23
+
### `YCalendarView` (SwiftUI)
24
+
`YCalendarView` is a struct that conforms to the SwiftUI `View` protocol.
25
+
20
26
### Initializers
21
27
28
+
Both `YCalendarPicker` and `YCalendarView` can be initialized with the same five parameters (`YCalendarPicker` uses `YCalendarView` internally):
29
+
22
30
```swift
23
31
init(
24
32
firstWeekday: Int?=nil,
@@ -28,18 +36,22 @@ init(
28
36
locale: Locale?=nil
29
37
)
30
38
```
31
-
The standard initializer lets you specify the first day of the week, appearance, optional minimum and maximum dates, and the locale although it provides sensible defaults for all of these.
39
+
The standard initializer lets you specify the first day of the week, appearance, optional minimum and maximum dates, and the locale, although it provides sensible defaults for all of these.
40
+
41
+
`YCalendarPicker` has an additional initializer:
32
42
33
43
```swift
34
44
init?(coder: NSCoder)
35
45
```
36
-
For use in Interface Builder or Storyboards. (Really though you should be building your UI in code.) It begins with the default appearance, but you can customize it at runtime by updating its `appearance`.
46
+
For use in Interface Builder or Storyboards (although we recommend that you build your UI in code).
47
+
48
+
A calendar picker created this way begins with the default appearance, but you can customize it at runtime by updating its `appearance` property.
37
49
38
50
### Customization
39
51
40
-
`YCalendarPicker`has an `appearance` property of type `Appearance`.
52
+
`YCalendarPicker`and `YCalendarView` both have an `appearance` property of type `Appearance`.
41
53
42
-
`Appearance` lets you customize the picker's appearance. You have full control over the colors, typographies, and images used. The default appearance is dark mode compatible and WCAG 2.0 AA compliant.
54
+
`Appearance` lets you customize the picker's appearance. You have full control over the colors, typographies, and images used. The default appearance is dark mode compatible and WCAG 2.0 AA compliant for color contrast.
43
55
44
56
```swift
45
57
/// Appearance for YCalendarPicker that contains typography and color properties
@@ -117,7 +129,7 @@ public struct Day {
117
129
view.addSubview(calendarPicker)
118
130
```
119
131
120
-
3. **Update or customize appearance**
132
+
3. **Customize and then update appearance**
121
133
122
134
```swift
123
135
// Create a calendar picker with the weekday text color set to green
@@ -186,7 +198,58 @@ Our calendar picker also supports Swift UI!
186
198
}
187
199
```
188
200
189
-
3. **Receive change notifications**
201
+
3. **Customize and then update appearance**
202
+
203
+
```swift
204
+
structCustomCalendar {
205
+
@Statevar calendar: YCalendarView = {
206
+
// Create a calendar picker with the weekday text color set to green
// set minimum date to yesterday and maximum date to tomorrow
239
+
calendar.minimumDate=Date().previousDate()
240
+
calendar.maximumDate=Date().nextDate()
241
+
}
242
+
Button("Select Today") {
243
+
// select today's date
244
+
calendar.date=Date()
245
+
}
246
+
}
247
+
}
248
+
}
249
+
250
+
```
251
+
252
+
5. **Receive change notifications**
190
253
To be notified when the user selects a date or changes the month, you can use the `delegate` property and conform to the `YCalendarViewDelegate` protocol.
0 commit comments