forked from SwiftKickMobile/SwiftMessages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountedViewController.swift
45 lines (38 loc) · 1.34 KB
/
CountedViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// CountedViewController.swift
// Demo
//
// Created by Timothy Moose on 8/25/17.
// Copyright © 2017 SwiftKick Mobile. All rights reserved.
//
import UIKit
import SwiftMessages
class CountedViewController: UIViewController {
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet var messageView: CountedMessageView!
@IBOutlet weak var messageContainer: UIView!
override func viewDidLoad() {
super.viewDidLoad()
descriptionLabel.configureBodyTextStyle()
descriptionLabel.configureCodeStyle(on: "show()")
descriptionLabel.configureCodeStyle(on: "hideCounted(id:)")
}
@IBAction func show() {
var config = SwiftMessages.defaultConfig
config.presentationStyle = .center
config.duration = .forever
config.presentationContext = .view(messageContainer)
SwiftMessages.show(config: config, view: messageView)
updateCountLabel()
}
@IBAction func hide() {
SwiftMessages.hideCounted(id: messageView.id)
updateCountLabel()
}
private func updateCountLabel() {
let count = SwiftMessages.count(id: messageView.id)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .spellOut
messageView.countLabel.text = numberFormatter.string(from: NSNumber(value: count))?.uppercased()
}
}