Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Symbol Position add #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 88 additions & 38 deletions SpringText/Classes/SPLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
import UIKit

open class SPLabel: UILabel {

public enum SymbolPosition {
case front
case back
}

private var fullText = ""

open var isCurrency = true

private var currencySymbol: String = "$"
open var showSymbol = true
private var symbolPosition: SymbolPosition = .front
private var scrollLayers: [CAScrollLayer] = []
private var scrollLabels: [UILabel] = []
private let duration = 0.7
Expand All @@ -26,8 +33,9 @@ open class SPLabel: UILabel {
self.animate()
}

public func setCurrency(symbol: String) {
public func setCurrency(symbol: String, symbolPosition: SymbolPosition) {
self.currencySymbol = symbol
self.symbolPosition = symbolPosition
}

private func configure(with number: Int) {
Expand Down Expand Up @@ -77,43 +85,85 @@ open class SPLabel: UILabel {
x = -w
}

if showSymbol {
let wLabel = UILabel()
wLabel.frame.origin = CGPoint(x: x, y: y)
wLabel.textColor = textColor
wLabel.font = font
wLabel.text = "\(currencySymbol) "
wLabel.textAlignment = .center
wLabel.sizeToFit()
self.addSubview(wLabel)
x += wLabel.bounds.width
}

stringArray.enumerated().forEach { index, text in
if textsNotAnimated.contains(text) {
// 콤마
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = text
label.textAlignment = .center
label.sizeToFit()
self.addSubview(label)

x += label.bounds.width
} else {
// 숫자
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = "0"
label.textAlignment = .center
label.sizeToFit()
createScrollLayer(to: label, text: text)

x += label.bounds.width
switch symbolPosition {
case .front:
if showSymbol {
let wLabel = UILabel()
wLabel.frame.origin = CGPoint(x: x, y: y)
wLabel.textColor = textColor
wLabel.font = font
wLabel.text = "\(currencySymbol) "
wLabel.textAlignment = .center
wLabel.sizeToFit()
self.addSubview(wLabel)
x += wLabel.bounds.width
}
stringArray.enumerated().forEach { index, text in
if textsNotAnimated.contains(text) {
// 콤마
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = text
label.textAlignment = .center
label.sizeToFit()
self.addSubview(label)

x += label.bounds.width
} else {
// 숫자
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = "0"
label.textAlignment = .center
label.sizeToFit()
createScrollLayer(to: label, text: text)

x += label.bounds.width
}
}
case .back:
stringArray.enumerated().forEach { index, text in
if textsNotAnimated.contains(text) {
// 콤마
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = text
label.textAlignment = .center
label.sizeToFit()
self.addSubview(label)

x += label.bounds.width
} else {
// 숫자
let label = UILabel()
label.frame.origin = CGPoint(x: x, y: y)
label.textColor = textColor
label.font = font
label.text = "0"
label.textAlignment = .center
label.sizeToFit()
createScrollLayer(to: label, text: text)

x += label.bounds.width
}
}

if showSymbol {
let wLabel = UILabel()
wLabel.frame.origin = CGPoint(x: x, y: y)
wLabel.textColor = textColor
wLabel.font = font
wLabel.text = "\(currencySymbol) "
wLabel.textAlignment = .center
wLabel.sizeToFit()
self.addSubview(wLabel)
x += wLabel.bounds.width
}
}
}
Expand Down