diff --git a/Application/Source/Detail/View/DetailView.swift b/Application/Source/Detail/View/DetailView.swift index b485544..ae93f66 100644 --- a/Application/Source/Detail/View/DetailView.swift +++ b/Application/Source/Detail/View/DetailView.swift @@ -3,9 +3,9 @@ import SnapKit class DetailView: UIView { - let title = UILabel.centeredLabel() + let title = UILabel() let button = UIButton() - let selectionResult = UILabel.centeredLabel() + let selectionResult = UILabel() private let spacingView: UIView = { let view = UIView() @@ -13,8 +13,8 @@ class DetailView: UIView { return view }() - let foodListTitle = UILabel.centeredLabel() - let foodList = UILabel.centeredLabel() + let foodListTitle = UILabel() + let foodList = UILabel() let foodInfoButton = UIButton() private(set) lazy var stackView: UIStackView = { diff --git a/Application/Source/Extensions/Extensions.swift b/Application/Source/Extensions/Extensions.swift deleted file mode 100644 index c84dc62..0000000 --- a/Application/Source/Extensions/Extensions.swift +++ /dev/null @@ -1,11 +0,0 @@ -import UIKit - -extension UILabel { - - static func centeredLabel() -> UILabel { - let label = UILabel() - label.textAlignment = .center - label.numberOfLines = 0 - return label - } -} diff --git a/Application/Source/Home/View/HomeView.swift b/Application/Source/Home/View/HomeView.swift index 4055ae7..7167175 100644 --- a/Application/Source/Home/View/HomeView.swift +++ b/Application/Source/Home/View/HomeView.swift @@ -3,7 +3,7 @@ import SnapKit class HomeView: UIView { - let label = UILabel.centeredLabel() + let label = UILabel() let imageView: UIImageView = { let imageView = UIImageView() diff --git a/Core/Source/Themes/Styles/LabelStyle.swift b/Core/Source/Themes/Styles/LabelStyle.swift index f52a70c..5322be6 100644 --- a/Core/Source/Themes/Styles/LabelStyle.swift +++ b/Core/Source/Themes/Styles/LabelStyle.swift @@ -4,6 +4,8 @@ import UIKit public struct LabelStyle: UILabelStyle { public let textColor: UIColor + public let numberOfLines: Int = 0 + public let textAlignment: NSTextAlignment = .center public init(theme: Theme) { textColor = theme.color.bodyText @@ -14,6 +16,8 @@ public struct LabelStyle: UILabelStyle { public struct AlternateLabelStyle: UILabelStyle { public let textColor: UIColor + public let numberOfLines: Int = 0 + public let textAlignment: NSTextAlignment = .center public init(theme: Theme) { textColor = theme.color.alternateBodyText diff --git a/Themer/Source/UIKit/UILabelStyle.swift b/Themer/Source/UIKit/UILabelStyle.swift index 49e17e1..218fa22 100644 --- a/Themer/Source/UIKit/UILabelStyle.swift +++ b/Themer/Source/UIKit/UILabelStyle.swift @@ -2,10 +2,16 @@ import UIKit public protocol UILabelStyle: Style where Styleable: UILabel { var textColor: UIColor { get } + var textAlignment: NSTextAlignment { get } + var numberOfLines: Int { get } } public extension UILabelStyle { + public func apply(to styleable: UILabel) { styleable.textColor = textColor + styleable.textAlignment = textAlignment + styleable.numberOfLines = numberOfLines } + } diff --git a/Themer/Tests/Stubs/StubUILabelStyle.swift b/Themer/Tests/Stubs/StubUILabelStyle.swift index 22b6dd5..d002a68 100644 --- a/Themer/Tests/Stubs/StubUILabelStyle.swift +++ b/Themer/Tests/Stubs/StubUILabelStyle.swift @@ -4,5 +4,7 @@ import UIKit struct StubUILabelStyle: UILabelStyle { let textColor: UIColor + let textAlignment: NSTextAlignment + let numberOfLines: Int } diff --git a/Themer/Tests/UILabelStyleSpec.swift b/Themer/Tests/UILabelStyleSpec.swift index 35b2f04..92caa0d 100644 --- a/Themer/Tests/UILabelStyleSpec.swift +++ b/Themer/Tests/UILabelStyleSpec.swift @@ -10,15 +10,23 @@ class UILabelStyleSpec: QuickSpec { describe("UILabelStyle") { it("should update appropriate values") { let textColor: UIColor = .red + let textAlignment: NSTextAlignment = .right + let numberOfLines = 99 let style = StubUILabelStyle( - textColor: textColor) + textColor: textColor, + textAlignment: textAlignment, + numberOfLines: numberOfLines) let label = UILabel() expect(label.textColor).notTo(equal(textColor)) + expect(label.textAlignment).notTo(equal(textAlignment)) + expect(label.numberOfLines).notTo(equal(numberOfLines)) style.apply(to: label) expect(label.textColor).to(equal(textColor)) + expect(label.textAlignment).to(equal(textAlignment)) + expect(label.numberOfLines).to(equal(numberOfLines)) } }