Skip to content

Commit b000bc2

Browse files
committed
Add SPLabelExtension.swift
1 parent 0ee594a commit b000bc2

File tree

4 files changed

+60
-59
lines changed

4 files changed

+60
-59
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SpringText/Classes/ReplaceMe.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

SpringText/Classes/SPLabel.swift

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,6 @@
77

88
import UIKit
99

10-
extension UILabel {
11-
func textWidth() -> CGFloat {
12-
return UILabel.textWidth(label: self)
13-
}
14-
15-
class func textWidth(label: UILabel) -> CGFloat {
16-
return textWidth(label: label, text: label.text!)
17-
}
18-
19-
class func textWidth(label: UILabel, text: String) -> CGFloat {
20-
return textWidth(font: label.font, text: text)
21-
}
22-
23-
class func textWidth(font: UIFont, text: String) -> CGFloat {
24-
let myText = text as NSString
25-
26-
let rect = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
27-
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: font], context: nil)
28-
return ceil(labelSize.width)
29-
}
30-
}
31-
32-
extension Int {
33-
var currency: String {
34-
let numberFormatter = NumberFormatter()
35-
numberFormatter.numberStyle = .decimal
36-
// numberFormatter.locale = App.shared.locale
37-
numberFormatter.maximumFractionDigits = 0
38-
return numberFormatter.string(from: NSNumber(value: self))?.currency ?? "0"
39-
}
40-
}
41-
42-
extension String {
43-
var currency: String {
44-
let formatter = NumberFormatter()
45-
formatter.numberStyle = .decimal
46-
// formatter.locale = App.shared.locale
47-
formatter.maximumFractionDigits = 0
48-
49-
let currencyString = formatter.string(from: formatter.number(from: self) ?? 0) ?? "0"
50-
// currencyString = currencyString + "원"
51-
52-
return currencyString
53-
}
54-
55-
}
56-
5710
open class TPCountLabel: UILabel {
5811
var fullText = ""
5912
private var hasWon: Bool = true
@@ -77,7 +30,7 @@ open class TPCountLabel: UILabel {
7730
setupSubviews()
7831
}
7932

80-
func animate(ascending: Bool = true) {
33+
private func animate(ascending: Bool = true) {
8134
createAnimations(ascending: ascending)
8235
}
8336

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// SPLabelExtension.swift
3+
// SpringText
4+
//
5+
// Created by seojin on 2020/10/11.
6+
//
7+
8+
import UIKit
9+
10+
extension UILabel {
11+
func textWidth() -> CGFloat {
12+
return UILabel.textWidth(label: self)
13+
}
14+
15+
class func textWidth(label: UILabel) -> CGFloat {
16+
return textWidth(label: label, text: label.text!)
17+
}
18+
19+
class func textWidth(label: UILabel, text: String) -> CGFloat {
20+
return textWidth(font: label.font, text: text)
21+
}
22+
23+
class func textWidth(font: UIFont, text: String) -> CGFloat {
24+
let myText = text as NSString
25+
26+
let rect = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
27+
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: font], context: nil)
28+
return ceil(labelSize.width)
29+
}
30+
}
31+
32+
extension Int {
33+
var currency: String {
34+
let numberFormatter = NumberFormatter()
35+
numberFormatter.numberStyle = .decimal
36+
// numberFormatter.locale = App.shared.locale
37+
numberFormatter.maximumFractionDigits = 0
38+
return numberFormatter.string(from: NSNumber(value: self))?.currency ?? "0"
39+
}
40+
}
41+
42+
extension String {
43+
var currency: String {
44+
let formatter = NumberFormatter()
45+
formatter.numberStyle = .decimal
46+
// formatter.locale = App.shared.locale
47+
formatter.maximumFractionDigits = 0
48+
49+
let currencyString = formatter.string(from: formatter.number(from: self) ?? 0) ?? "0"
50+
// currencyString = currencyString + "원"
51+
52+
return currencyString
53+
}
54+
55+
}

0 commit comments

Comments
 (0)