File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ MagicTimer is a UIView based timer that displays a countdown or count-up timer.<
22
22
## Features
23
23
- [x] Fully customizable design
24
24
- [x] Support stop watch / count down mode
25
+ - [x] Support custom time formatter
25
26
- [x] Suppport in background time calculation
26
27
- [x] Modifable time interval / step
27
28
- [x] Fully Managable: start, pause, reset
@@ -135,7 +136,28 @@ A callback that notifies when timer state did change.
135
136
``` swift
136
137
public var didStateChange: ((MGStateManager.TimerState) -> Void )?
137
138
```
139
+ # Formatter
140
+ MagicTimerView can accept custom time formatter. Any time formatter should confrom ` MGTimeFormatter ` .
141
+ ### ` MGTimeFormatter `
142
+ ``` swift
143
+ public protocol MGTimeFormatter
144
+ ```
145
+ Sample custom time formatter
146
+ ```swift
138
147
148
+ class CustomTimeFormatter: MGTimeFormatter {
149
+ let dateComponent = DateComponentsFormatter ()
150
+
151
+ init () {
152
+ dateComponent.unitsStyle = .positional
153
+ dateComponent.allowedUnits = [.second ]
154
+ }
155
+ func converToValidFormat (ti : TimeInterval) -> String ? {
156
+ dateComponent.string (from : ti)
157
+ }
158
+ }
159
+
160
+ ```
139
161
# Observe
140
162
You can observe elapsed time in two ways. <br />
141
163
** First** : using ` elapsedTime ` property.
You can’t perform that action at this time.
0 commit comments