Skip to content

Commit 7193f82

Browse files
author
Russell Warwick
committed
Adds .withBackground that allows users to pass through a background color to any view
1 parent e3b04f3 commit 7193f82

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

Example/Example/Flow/Home/Examples/VerticalExampleViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ final class VerticalExampleViewController: UIViewController {
5656
label
5757
Spacer()
5858
}.margin(.top(20))
59+
.withBackground(.red)
5960
}
6061
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Russell Warwick on 03/07/2021.
6+
//
7+
8+
import UIKit
9+
10+
public final class Spacer: UIView {
11+
12+
// MARK: - Init
13+
14+
public init() {
15+
super.init(frame: .zero)
16+
}
17+
18+
public init(w: CGFloat) {
19+
super.init(frame: .zero)
20+
translatesAutoresizingMaskIntoConstraints = false
21+
widthAnchor.constraint(equalToConstant: w).isActive = true
22+
}
23+
24+
public init(h: CGFloat) {
25+
super.init(frame: .zero)
26+
translatesAutoresizingMaskIntoConstraints = false
27+
heightAnchor.constraint(equalToConstant: h).isActive = true
28+
}
29+
30+
required public init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Russell Warwick on 03/07/2021.
6+
//
7+
8+
import UIKit
9+
10+
public extension UIView {
11+
@discardableResult
12+
func withBackground(_ color: UIColor) -> Self {
13+
backgroundColor = color
14+
return self
15+
}
16+
}
17+

Sources/SharkStackKit/Stacks/Stacks.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public extension UIView {
3131
}
3232
}
3333

34-
3534
public final class ZStack: UIView {
3635

3736
public init(spacing: CGFloat = .zero, @UIViewBuilder views: () -> [UIView]) {
@@ -108,29 +107,6 @@ public extension UIStackView {
108107
}
109108
}
110109

111-
public final class Spacer: UIView {
112-
113-
// MARK: - Init
114-
115-
public init() {
116-
super.init(frame: .zero)
117-
}
118-
119-
public init(w: CGFloat) {
120-
super.init(frame: .zero)
121-
translatesAutoresizingMaskIntoConstraints = false
122-
widthAnchor.constraint(equalToConstant: w).isActive = true
123-
}
124-
125-
public init(h: CGFloat) {
126-
super.init(frame: .zero)
127-
translatesAutoresizingMaskIntoConstraints = false
128-
heightAnchor.constraint(equalToConstant: h).isActive = true
129-
}
130-
131-
required public init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
132-
}
133-
134110
extension UIView {
135111

136112
@discardableResult

0 commit comments

Comments
 (0)