Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove centeredLabel extension in favor of UILabelStyle additions
Browse files Browse the repository at this point in the history
lokae0 committed Jan 24, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2d7a294 commit dddaa52
Showing 7 changed files with 26 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Application/Source/Detail/View/DetailView.swift
Original file line number Diff line number Diff line change
@@ -3,18 +3,18 @@ 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()
view.snp.makeConstraints { $0.height.equalTo(35) }
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 = {
11 changes: 0 additions & 11 deletions Application/Source/Extensions/Extensions.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Application/Source/Home/View/HomeView.swift
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import SnapKit

class HomeView: UIView {

let label = UILabel.centeredLabel()
let label = UILabel()

let imageView: UIImageView = {
let imageView = UIImageView()
4 changes: 4 additions & 0 deletions Core/Source/Themes/Styles/LabelStyle.swift
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Themer/Source/UIKit/UILabelStyle.swift
Original file line number Diff line number Diff line change
@@ -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
}

}
2 changes: 2 additions & 0 deletions Themer/Tests/Stubs/StubUILabelStyle.swift
Original file line number Diff line number Diff line change
@@ -4,5 +4,7 @@ import UIKit
struct StubUILabelStyle: UILabelStyle {

let textColor: UIColor
let textAlignment: NSTextAlignment
let numberOfLines: Int

}
10 changes: 9 additions & 1 deletion Themer/Tests/UILabelStyleSpec.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}

0 comments on commit dddaa52

Please sign in to comment.