forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimalTextFieldTableViewCell.swift
More file actions
47 lines (37 loc) · 1.1 KB
/
Copy pathDecimalTextFieldTableViewCell.swift
File metadata and controls
47 lines (37 loc) · 1.1 KB
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
46
//
// DecimalTextFieldTableViewCell.swift
// CarbKit
//
// Created by Nathan Racklyeft on 1/15/16.
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
//
import UIKit
public class DecimalTextFieldTableViewCell: TextFieldTableViewCell {
@IBOutlet weak var titleLabel: UILabel!
var numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter
}()
public var number: NSNumber? {
get {
return numberFormatter.number(from: textField.text ?? "")
}
set {
if let value = newValue {
textField.text = numberFormatter.string(from: value)
} else {
textField.text = nil
}
}
}
// MARK: - UITextFieldDelegate
public override func textFieldDidEndEditing(_ textField: UITextField) {
if let number = number {
textField.text = numberFormatter.string(from: number)
} else {
textField.text = nil
}
super.textFieldDidEndEditing(textField)
}
}