forked from euwars/browser-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewUtil.swift
33 lines (30 loc) · 1.19 KB
/
ViewUtil.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import SnapKit
extension UIView {
/// Creates empty view with specified height or width parameter.
/// Used mainly to make empty space for UIStackView
/// Note: on iOS 11+ setCustomSpacing(value, after: View) can be used instead.
static func spacer(_ direction: UILayoutConstraintAxis, amount: Int) -> UIView {
let spacer = UIView()
spacer.snp.makeConstraints { make in
switch direction {
case .vertical:
make.height.equalTo(amount)
case .horizontal:
make.width.equalTo(amount)
}
}
return spacer
}
/// Returns regular constraint layout DSL or uses safeAreaLayoutGuide if possible(iOS11+).
/// This removes need of having to check for iOS availability for every constraint setup.
var safeArea: ConstraintAttributesDSL {
if #available(iOS 11.0, *) {
return self.safeAreaLayoutGuide.snp
}
return self.snp
}
}