Skip to content

Commit 6e4a78a

Browse files
committed
0.1.9
1 parent 1a2636f commit 6e4a78a

9 files changed

Lines changed: 339 additions & 194 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# CHANGELOG
22

33

4+
* Feature/Empty_Label_Support/0.1.9
5+
6+
+ Cleaned up testbed views
7+
48
* Feature/Empty_Label_Support/0.1.8
59

610
+ Cleanup files and folders

UILabel_Typography_Extensions.xcodeproj/project.pbxproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5501DB9127D81E70009E0FDA /* EmptyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5501DB9027D81E70009E0FDA /* EmptyViewController.swift */; };
11+
5501DB9327D81EC9009E0FDA /* ManualViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5501DB9227D81EC9009E0FDA /* ManualViewController.swift */; };
12+
5501DB9527D82099009E0FDA /* UIButton+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5501DB9427D82099009E0FDA /* UIButton+Extensions.swift */; };
13+
5501DB9727D8240E009E0FDA /* UIButton+Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5501DB9627D8240E009E0FDA /* UIButton+Styles.swift */; };
1014
551B425F259BCE40001310A9 /* UIFont+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B425E259BCE40001310A9 /* UIFont+Extensions.swift */; };
1115
554AF31825961B6200A23E41 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 554AF31725961B6200A23E41 /* README.md */; };
1216
559795E525A259E400A757A3 /* UIColor+Styles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 559795E425A259E400A757A3 /* UIColor+Styles.swift */; };
@@ -16,7 +20,7 @@
1620
55F236A425912BBE0007BC69 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236A325912BBE0007BC69 /* SceneDelegate.swift */; };
1721
55F236A825912BC30007BC69 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55F236A725912BC30007BC69 /* Assets.xcassets */; };
1822
55F236AE25912BC30007BC69 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 55F236AC25912BC30007BC69 /* LaunchScreen.storyboard */; };
19-
55F236B725912BF20007BC69 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236B625912BF20007BC69 /* ViewController.swift */; };
23+
55F236B725912BF20007BC69 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236B625912BF20007BC69 /* MenuViewController.swift */; };
2024
55F236BB25912C430007BC69 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236BA25912C430007BC69 /* Withable.swift */; };
2125
55F236BF25912C710007BC69 /* UIKit+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236BD25912C700007BC69 /* UIKit+Extensions.swift */; };
2226
55F236CA25912E690007BC69 /* PreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F236C925912E690007BC69 /* PreviewView.swift */; };
@@ -30,6 +34,10 @@
3034
/* End PBXBuildFile section */
3135

3236
/* Begin PBXFileReference section */
37+
5501DB9027D81E70009E0FDA /* EmptyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyViewController.swift; sourceTree = "<group>"; };
38+
5501DB9227D81EC9009E0FDA /* ManualViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualViewController.swift; sourceTree = "<group>"; };
39+
5501DB9427D82099009E0FDA /* UIButton+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Extensions.swift"; sourceTree = "<group>"; };
40+
5501DB9627D8240E009E0FDA /* UIButton+Styles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Styles.swift"; sourceTree = "<group>"; };
3341
551B425E259BCE40001310A9 /* UIFont+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extensions.swift"; sourceTree = "<group>"; };
3442
554A2DCF27D67B66008A4AE4 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
3543
554AF31725961B6200A23E41 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -42,7 +50,7 @@
4250
55F236A725912BC30007BC69 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4351
55F236AD25912BC30007BC69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4452
55F236AF25912BC30007BC69 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
45-
55F236B625912BF20007BC69 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
53+
55F236B625912BF20007BC69 /* MenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = "<group>"; };
4654
55F236BA25912C430007BC69 /* Withable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Withable.swift; sourceTree = "<group>"; };
4755
55F236BD25912C700007BC69 /* UIKit+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+Extensions.swift"; sourceTree = "<group>"; };
4856
55F236C925912E690007BC69 /* PreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewView.swift; sourceTree = "<group>"; };
@@ -94,11 +102,15 @@
94102
55A3EECF27D7F32E0002193A /* View */ = {
95103
isa = PBXGroup;
96104
children = (
97-
55F236B625912BF20007BC69 /* ViewController.swift */,
105+
55F236B625912BF20007BC69 /* MenuViewController.swift */,
106+
5501DB9227D81EC9009E0FDA /* ManualViewController.swift */,
107+
5501DB9027D81E70009E0FDA /* EmptyViewController.swift */,
98108
55F7E34725A0AD7F00E7F48B /* AttributesViewController.swift */,
99109
55F7E34325A0AA5E00E7F48B /* GlyphViewController.swift */,
100110
559FB34D25A4B1A200CE795D /* LineHeightViewController.swift */,
101111
55F7E34025A0A91E00E7F48B /* LoremIpsumViewController.swift */,
112+
5501DB9427D82099009E0FDA /* UIButton+Extensions.swift */,
113+
5501DB9627D8240E009E0FDA /* UIButton+Styles.swift */,
102114
);
103115
path = View;
104116
sourceTree = "<group>";
@@ -222,19 +234,23 @@
222234
55F236A225912BBE0007BC69 /* AppDelegate.swift in Sources */,
223235
55F7F0A2259A6F03001BEF90 /* Typography.swift in Sources */,
224236
55F236CA25912E690007BC69 /* PreviewView.swift in Sources */,
237+
5501DB9327D81EC9009E0FDA /* ManualViewController.swift in Sources */,
225238
559FB34E25A4B1A200CE795D /* LineHeightViewController.swift in Sources */,
239+
5501DB9727D8240E009E0FDA /* UIButton+Styles.swift in Sources */,
226240
55F7E33225A03D8300E7F48B /* UILabel+Observer.swift in Sources */,
227241
55F236BB25912C430007BC69 /* Withable.swift in Sources */,
228242
55F7E34425A0AA5E00E7F48B /* GlyphViewController.swift in Sources */,
229243
55F236BF25912C710007BC69 /* UIKit+Extensions.swift in Sources */,
230244
55A3EECE27D7F24C0002193A /* UIFont+Inspection.swift in Sources */,
231245
55F236A425912BBE0007BC69 /* SceneDelegate.swift in Sources */,
232246
551B425F259BCE40001310A9 /* UIFont+Extensions.swift in Sources */,
247+
5501DB9527D82099009E0FDA /* UIButton+Extensions.swift in Sources */,
233248
55F7E34125A0A91E00E7F48B /* LoremIpsumViewController.swift in Sources */,
234249
559795E525A259E400A757A3 /* UIColor+Styles.swift in Sources */,
235250
55F7E34825A0AD7F00E7F48B /* AttributesViewController.swift in Sources */,
236-
55F236B725912BF20007BC69 /* ViewController.swift in Sources */,
251+
55F236B725912BF20007BC69 /* MenuViewController.swift in Sources */,
237252
55F7E33E25A051FE00E7F48B /* UILabel+Grid.swift in Sources */,
253+
5501DB9127D81E70009E0FDA /* EmptyViewController.swift in Sources */,
238254
);
239255
runOnlyForDeploymentPostprocessing = 0;
240256
};

UILabel_Typography_Extensions/SceneDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2121
// Use a UIHostingController as window root view controller.
2222
if let windowScene = scene as? UIWindowScene {
2323
let window = UIWindow(windowScene: windowScene)
24-
window.rootViewController = ViewController()
24+
window.rootViewController = MenuViewController()
2525
self.window = window
2626
window.makeKeyAndVisible()
2727
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// EmptyViewController.swift
3+
// UILabel_Typography_Extensions
4+
//
5+
// Created by Geri Borbás on 09/03/2022.
6+
//
7+
8+
import UIKit
9+
10+
11+
class EmptyViewController: UIViewController {
12+
13+
let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
14+
15+
lazy var label = UILabel()
16+
.with {
17+
18+
// Properties.
19+
$0.font = UIFont.newYork(ofSize: 1024.0 / 26.0)
20+
$0.textColor = .text
21+
$0.layer.compositingFilter = "multiplyBlendMode"
22+
$0.numberOfLines = 0
23+
$0.showGrid = true
24+
$0.lineHeight = CGFloat(87)
25+
$0.underline = .double
26+
$0.textAlignment = .center
27+
28+
// Set text after.
29+
$0.text = loremIpsum
30+
31+
}.inspect
32+
33+
var models: [(text: String, backgroundColor: UIColor)] = [
34+
("Lorem ipsum dolor sit amet.", UIColor.systemBlue.withAlphaComponent(0.1)),
35+
("Consectetur adipiscing elit.", UIColor.systemGreen.withAlphaComponent(0.1)),
36+
("", UIColor.clear),
37+
("Sed do eiusmod tempor incididunt ut labore.", UIColor.systemOrange.withAlphaComponent(0.1)),
38+
("Et dolore magna aliqua.", UIColor.systemIndigo.withAlphaComponent(0.1))
39+
]
40+
41+
lazy var body = UIStackView()
42+
.vertical(spacing: 10)
43+
.views(
44+
label,
45+
UIButton()
46+
.with(title: "Change text")
47+
.onTouchUpInside { [unowned self] in
48+
if models.isEmpty == false {
49+
let model = models.removeFirst()
50+
label.text = model.text
51+
label.backgroundColor = model.backgroundColor
52+
}
53+
},
54+
UIView
55+
.spacer
56+
.inspect
57+
)
58+
59+
override func viewDidLoad() {
60+
super.viewDidLoad()
61+
view.addSubview(body)
62+
view.backgroundColor = .systemBackground
63+
body.pin(
64+
to: view.safeAreaLayoutGuide,
65+
insets: UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
66+
)
67+
}
68+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// ManualViewController.swift
3+
// UILabel_Typography_Extensions
4+
//
5+
// Created by Geri Borbás on 09/03/2022.
6+
//
7+
8+
import UIKit
9+
10+
11+
class ManualViewController: UIViewController {
12+
13+
lazy var label: UILabel = {
14+
15+
// Properties.
16+
let label = UILabel()
17+
label.font = UIFont.newYork(ofSize: 1024.0 / 26.0)
18+
label.textColor = .text
19+
label.layer.compositingFilter = "multiplyBlendMode"
20+
label.numberOfLines = 0
21+
label.showGrid = true
22+
23+
// Text.
24+
label.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
25+
26+
// Line height.
27+
let paragraphStyle = NSMutableParagraphStyle()
28+
paragraphStyle.minimumLineHeight = CGFloat(87)
29+
paragraphStyle.maximumLineHeight = CGFloat(87)
30+
label.attributedText = NSAttributedString(
31+
string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
32+
attributes: [
33+
.baselineOffset : 10, // (87 - 47) / 2 / 2
34+
.paragraphStyle : paragraphStyle
35+
]
36+
)
37+
38+
return label
39+
}()
40+
41+
lazy var body = UIStackView()
42+
.vertical(spacing: 10)
43+
.views(
44+
label,
45+
UIView
46+
.spacer
47+
.inspect
48+
)
49+
50+
override func viewDidLoad() {
51+
super.viewDidLoad()
52+
view.addSubview(body)
53+
view.backgroundColor = .systemBackground
54+
body.pin(
55+
to: view.safeAreaLayoutGuide,
56+
insets: UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
57+
)
58+
}
59+
}
60+
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// MenuViewController.swift
3+
// Label_Extensions
4+
//
5+
// Copyright © 2020. Geri Borbás. All rights reserved.
6+
// https://twitter.com/Geri_Borbas
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in all
16+
// copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
// SOFTWARE.
25+
//
26+
27+
import UIKit
28+
29+
30+
class MenuViewController: UIViewController {
31+
32+
lazy var body = UIStackView()
33+
.vertical(spacing: 10)
34+
.views(
35+
UIButton()
36+
.with(title: "Manual Label Styling")
37+
.onTouchUpInside { [unowned self] in
38+
self.present(ManualViewController(), animated: true)
39+
}
40+
,
41+
UIButton()
42+
.with(title: "Empty Label Styling")
43+
.onTouchUpInside { [unowned self] in
44+
self.present(EmptyViewController(), animated: true)
45+
},
46+
UIButton()
47+
.with(title: "Attributes")
48+
.onTouchUpInside { [unowned self] in
49+
self.present(AttributesViewController(), animated: true)
50+
},
51+
UIButton()
52+
.with(title: "Lorem Ipsum")
53+
.onTouchUpInside { [unowned self] in
54+
self.present(LoremIpsumViewController(), animated: true)
55+
},
56+
UIButton()
57+
.with(title: "Glyph")
58+
.onTouchUpInside { [unowned self] in
59+
self.present(GlyphViewController(), animated: true)
60+
},
61+
UIButton()
62+
.with(title: "Line Height")
63+
.onTouchUpInside { [unowned self] in
64+
self.present(LineHeightViewController(), animated: true)
65+
},
66+
UIView
67+
.spacer
68+
.inspect
69+
)
70+
71+
override func viewDidLoad() {
72+
super.viewDidLoad()
73+
view.addSubview(body)
74+
view.backgroundColor = .systemBackground
75+
body.pin(
76+
to: view.safeAreaLayoutGuide,
77+
insets: UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
78+
)
79+
}
80+
81+
override func viewDidAppear(_ animated: Bool) {
82+
super.viewDidAppear(animated)
83+
self.present(EmptyViewController(), animated: true)
84+
}
85+
}
86+
87+
88+
extension UILabel {
89+
90+
var withImages: Self {
91+
with {
92+
$0.leadingImage = Typography.Image(
93+
image: UIImage(named: "Star"),
94+
size: CGSize(width: font.capHeight, height: font.capHeight)
95+
)
96+
$0.trailingImage = Typography.Image(
97+
image: UIImage(named: "Star")!.withRenderingMode(.alwaysTemplate),
98+
size: CGSize(width: font.capHeight, height: font.capHeight)
99+
)
100+
}
101+
}
102+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// UIButton+Extensions.swift
3+
// UILabel_Typography_Extensions
4+
//
5+
// Created by Geri Borbás on 09/03/2022.
6+
//
7+
8+
import UIKit
9+
10+
11+
extension UIButton {
12+
13+
typealias Action = () -> Void
14+
15+
struct Keys {
16+
static var action: UInt8 = 0
17+
}
18+
19+
/// An attributed string property to cache typography even when the label text is empty.
20+
var action: Action? {
21+
get {
22+
objc_getAssociatedObject(self, &Keys.action) as? Action
23+
}
24+
set {
25+
objc_setAssociatedObject(self, &Keys.action, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
26+
}
27+
}
28+
29+
func onTouchUpInside(_ action: @escaping Action) -> Self {
30+
self.action = action
31+
addTarget(self, action: #selector(didTouchUpInside), for: .touchUpInside)
32+
return self
33+
}
34+
35+
@objc func didTouchUpInside() {
36+
action?()
37+
}
38+
}

0 commit comments

Comments
 (0)