Skip to content

Commit 65e4fd4

Browse files
Mark Pospeselmpospese
authored andcommitted
[Issue 1] Add extra examples to README
1 parent 37a9790 commit 65e4fd4

File tree

1 file changed

+69
-6
lines changed

1 file changed

+69
-6
lines changed

README.md

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ Documentation is automatically generated from source code comments and rendered
1717
Usage
1818
----------
1919

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+
2026
### Initializers
2127

28+
Both `YCalendarPicker` and `YCalendarView` can be initialized with the same five parameters (`YCalendarPicker` uses `YCalendarView` internally):
29+
2230
```swift
2331
init(
2432
firstWeekday: Int? = nil,
@@ -28,18 +36,22 @@ init(
2836
locale: Locale? = nil
2937
)
3038
```
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:
3242

3343
```swift
3444
init?(coder: NSCoder)
3545
```
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.
3749

3850
### Customization
3951

40-
`YCalendarPicker` has an `appearance` property of type `Appearance`.
52+
`YCalendarPicker` and `YCalendarView` both have an `appearance` property of type `Appearance`.
4153

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.
4355

4456
```swift
4557
/// Appearance for YCalendarPicker that contains typography and color properties
@@ -117,7 +129,7 @@ public struct Day {
117129
view.addSubview(calendarPicker)
118130
```
119131

120-
3. **Update or customize appearance**
132+
3. **Customize and then update appearance**
121133

122134
```swift
123135
// Create a calendar picker with the weekday text color set to green
@@ -186,7 +198,58 @@ Our calendar picker also supports Swift UI!
186198
}
187199
```
188200

189-
3. **Receive change notifications**
201+
3. **Customize and then update appearance**
202+
203+
```swift
204+
struct CustomCalendar {
205+
@State var calendar: YCalendarView = {
206+
// Create a calendar picker with the weekday text color set to green
207+
var calendar = YCalendarView()
208+
calendar.appearance.weekdayStyle.textColor = .green
209+
return calendar
210+
}()
211+
}
212+
213+
extension CustomCalendar: View {
214+
public var body: some View {
215+
VStack {
216+
calendar
217+
Button("Go Red") {
218+
// Change the weekday text color to red
219+
calendar.appearance.weekdayStyle.textColor = .red
220+
}
221+
}
222+
}
223+
}
224+
```
225+
226+
4. **Update Calendar properties**
227+
228+
```swift
229+
struct CustomCalendar {
230+
@State var calendar = YCalendarView()
231+
}
232+
233+
extension CustomCalendar: View {
234+
var body: some View {
235+
VStack {
236+
calendar
237+
Button("Set Min/Max") {
238+
// 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**
190253
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.
191254

192255
```swift

0 commit comments

Comments
 (0)