Skip to content

Commit a4b1471

Browse files
committed
Merge branch 'master' of https://github.com/sadeghgoo/MagicTimer
2 parents ccf8d8e + 3ed0926 commit a4b1471

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ MagicTimer is a UIView based timer that displays a countdown or count-up timer.<
2222
## Features
2323
- [x] Fully customizable design
2424
- [x] Support stop watch / count down mode
25+
- [x] Support custom time formatter
2526
- [x] Suppport in background time calculation
2627
- [x] Modifable time interval / step
2728
- [x] Fully Managable: start, pause, reset
@@ -135,7 +136,28 @@ A callback that notifies when timer state did change.
135136
```swift
136137
public var didStateChange: ((MGStateManager.TimerState) -> Void)?
137138
```
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
138147

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+
```
139161
# Observe
140162
You can observe elapsed time in two ways. <br />
141163
**First**: using `elapsedTime` property.

0 commit comments

Comments
 (0)