Skip to content

Commit 171b8bf

Browse files
committed
[ SJ.H ] : Add Background
1 parent 65c6889 commit 171b8bf

File tree

4 files changed

+89
-27
lines changed

4 files changed

+89
-27
lines changed

Example/SpringText/Base.lproj/Main.storyboard

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,64 @@
2020
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2121
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2222
<subviews>
23-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sIj-hc-Uk3" customClass="SPLabel" customModule="SpringText">
24-
<rect key="frame" x="36" y="20" width="303" height="21"/>
25-
<color key="backgroundColor" systemColor="systemPinkColor"/>
26-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
27-
<nil key="textColor"/>
28-
<nil key="highlightedColor"/>
29-
</label>
23+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3LM-BG-Htn">
24+
<rect key="frame" x="36" y="20" width="303" height="82"/>
25+
<subviews>
26+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="7yP-7o-4da">
27+
<rect key="frame" x="0.0" y="0.0" width="303" height="82"/>
28+
<subviews>
29+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qrS-6m-9He" customClass="SPLabel" customModule="SpringText">
30+
<rect key="frame" x="0.0" y="0.0" width="303" height="20.5"/>
31+
<color key="backgroundColor" systemColor="systemPinkColor"/>
32+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
33+
<nil key="textColor"/>
34+
<nil key="highlightedColor"/>
35+
</label>
36+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WBh-YJ-BoT" customClass="SPLabel" customModule="SpringText">
37+
<rect key="frame" x="0.0" y="20.5" width="303" height="20.5"/>
38+
<color key="backgroundColor" systemColor="systemPinkColor"/>
39+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
40+
<nil key="textColor"/>
41+
<nil key="highlightedColor"/>
42+
</label>
43+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Rf9-rt-EBr" customClass="SPLabel" customModule="SpringText">
44+
<rect key="frame" x="0.0" y="41" width="303" height="20.5"/>
45+
<color key="backgroundColor" systemColor="systemPinkColor"/>
46+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
47+
<nil key="textColor"/>
48+
<nil key="highlightedColor"/>
49+
</label>
50+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9iN-kW-35e" customClass="SPLabel" customModule="SpringText">
51+
<rect key="frame" x="0.0" y="61.5" width="303" height="20.5"/>
52+
<color key="backgroundColor" systemColor="systemPinkColor"/>
53+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
54+
<nil key="textColor"/>
55+
<nil key="highlightedColor"/>
56+
</label>
57+
</subviews>
58+
</stackView>
59+
</subviews>
60+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
61+
<constraints>
62+
<constraint firstItem="7yP-7o-4da" firstAttribute="top" secondItem="3LM-BG-Htn" secondAttribute="top" id="1rI-mN-dRX"/>
63+
<constraint firstAttribute="bottom" secondItem="7yP-7o-4da" secondAttribute="bottom" id="4GE-cQ-wXO"/>
64+
<constraint firstItem="7yP-7o-4da" firstAttribute="leading" secondItem="3LM-BG-Htn" secondAttribute="leading" id="6AU-ft-2es"/>
65+
<constraint firstAttribute="trailing" secondItem="7yP-7o-4da" secondAttribute="trailing" id="axb-91-Sqz"/>
66+
</constraints>
67+
</view>
3068
</subviews>
31-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
69+
<color key="backgroundColor" systemColor="systemTealColor"/>
3270
<constraints>
33-
<constraint firstItem="sIj-hc-Uk3" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="6B7-u4-i0a"/>
34-
<constraint firstItem="sIj-hc-Uk3" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="20" id="E34-np-fky"/>
35-
<constraint firstAttribute="trailingMargin" secondItem="sIj-hc-Uk3" secondAttribute="trailing" constant="20" id="tdT-yc-Eq0"/>
71+
<constraint firstAttribute="trailingMargin" secondItem="3LM-BG-Htn" secondAttribute="trailing" constant="20" id="WYg-5C-Mkb"/>
72+
<constraint firstItem="3LM-BG-Htn" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="20" id="kRI-LW-LDA"/>
73+
<constraint firstItem="3LM-BG-Htn" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="tSU-RG-g9K"/>
3674
</constraints>
3775
</view>
3876
<connections>
39-
<outlet property="lblTitle" destination="sIj-hc-Uk3" id="LcL-HP-JCM"/>
77+
<outlet property="lbl_num1" destination="qrS-6m-9He" id="CFT-NY-clj"/>
78+
<outlet property="lbl_num2" destination="WBh-YJ-BoT" id="jHa-oz-N7W"/>
79+
<outlet property="lbl_num3" destination="Rf9-rt-EBr" id="kMY-CQ-0dl"/>
80+
<outlet property="lbl_num4" destination="9iN-kW-35e" id="bXU-lr-i0d"/>
4081
</connections>
4182
</viewController>
4283
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
@@ -45,8 +86,14 @@
4586
</scene>
4687
</scenes>
4788
<resources>
89+
<systemColor name="systemBackgroundColor">
90+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
91+
</systemColor>
4892
<systemColor name="systemPinkColor">
4993
<color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5094
</systemColor>
95+
<systemColor name="systemTealColor">
96+
<color red="0.35294117647058826" green="0.78431372549019607" blue="0.98039215686274506" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
97+
</systemColor>
5198
</resources>
5299
</document>

Example/SpringText/ViewController.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@ import UIKit
1010
import SpringText
1111

1212
class ViewController: UIViewController {
13-
@IBOutlet weak var lblTitle: SPLabel!
13+
@IBOutlet weak var lbl_num1: SPLabel!
14+
@IBOutlet weak var lbl_num2: SPLabel!
15+
@IBOutlet weak var lbl_num3: SPLabel!
16+
@IBOutlet weak var lbl_num4: SPLabel!
1417

1518
override func viewDidLoad() {
16-
lblTitle.text(num: 28787123)
19+
lbl_num1.text(num: 1000000000)
20+
lbl_num2.text(num: 1000000000, showCurrency: true)
21+
lbl_num3.text(num: 1234567890)
22+
lbl_num4.setCurrency(symbol: "")
23+
lbl_num4.text(num: 1234567890, showCurrency:true)
24+
25+
let newLabel = SPLabel(frame: CGRect(x: 50, y: 200, width: 100, height: 100))
26+
newLabel.text(num: 1203901293)
27+
self.view.addSubview(newLabel)
1728
}
1829

1930
override func didReceiveMemoryWarning() {
2031
super.didReceiveMemoryWarning()
2132
// Dispose of any resources that can be recreated.
2233
}
23-
2434
}
2535

SpringText.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SpringText'
11-
s.version = '1.1.2'
11+
s.version = '1.1.3'
1212
s.summary = 'Summary SpringText.'
1313

1414
# This description is used to generate tags and improve search results.

SpringText/Classes/SPLabel.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ import UIKit
99

1010
open class SPLabel: UILabel {
1111
var fullText = ""
12-
private var hasWon: Bool = true
13-
12+
private var currencySymbol: String = "$"
13+
private var showCurrency: Bool = true
1414
private var scrollLayers: [CAScrollLayer] = []
1515
private var scrollLabels: [UILabel] = []
1616
private let duration = 0.7
1717
private let durationOffset = 0.2
1818
private let textsNotAnimated = [","]
1919

20-
public func text(num: Int, hasWon: Bool = true) {
21-
self.hasWon = hasWon
20+
public func text(num: Int, showCurrency: Bool = false) {
21+
self.showCurrency = showCurrency
2222
self.configure(with: num)
23+
self.text = " "
2324
self.animate()
2425
}
2526

26-
public func configure(with number: Int) {
27+
public func setCurrency(symbol: String) {
28+
self.currencySymbol = symbol
29+
}
30+
31+
private func configure(with number: Int) {
2732
let text = number.currency
2833
fullText = text
2934
clean()
@@ -47,17 +52,17 @@ open class SPLabel: UILabel {
4752
var x: CGFloat = 0
4853
let y: CGFloat = 0
4954
if self.textAlignment == .center {
50-
if hasWon {
51-
self.text = " \(fullText)"
55+
if showCurrency {
56+
self.text = "\(currencySymbol) \(fullText)"
5257
} else {
5358
self.text = fullText
5459
}
5560
let w = UILabel.textWidth(font: self.font, text: self.text ?? "")
5661
self.text = "" // 초기화
5762
x = -(w / 2)
5863
} else if self.textAlignment == .right {
59-
if hasWon {
60-
self.text = " \(fullText)"
64+
if showCurrency {
65+
self.text = "\(currencySymbol) \(fullText)"
6166
} else {
6267
self.text = fullText
6368
}
@@ -66,12 +71,12 @@ open class SPLabel: UILabel {
6671
x = -w
6772
}
6873

69-
if hasWon {
74+
if showCurrency {
7075
let wLabel = UILabel()
7176
wLabel.frame.origin = CGPoint(x: x, y: y)
7277
wLabel.textColor = textColor
7378
wLabel.font = font
74-
wLabel.text = " "
79+
wLabel.text = "\(currencySymbol) "
7580
wLabel.textAlignment = .center
7681
wLabel.sizeToFit()
7782
self.addSubview(wLabel)

0 commit comments

Comments
 (0)