Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit b8d5c85

Browse files
authored
Merge pull request #2 from hyperlinkgroup/develop
Release 1.0.1
2 parents da2abee + 67642a0 commit b8d5c85

File tree

5 files changed

+85
-71
lines changed

5 files changed

+85
-71
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// CellIdentifier.swift
3+
//
4+
//
5+
// Created by Anna Münster on 05.10.18.
6+
// Copyright © 2018 spacesquad. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UICollectionViewCell {
12+
public static var identifier: String {
13+
String(describing: self)
14+
}
15+
}
16+
17+
extension UITableViewCell {
18+
public static var identifier: String {
19+
String(describing: self)
20+
}
21+
}
22+
extension UITableViewHeaderFooterView {
23+
public static var identifier: String {
24+
String(describing: self)
25+
}
26+
}

Diff for: Sources/UIKitComponents/Extensions/Priorities.swift

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Priorities.swift
3+
//
4+
//
5+
// Created by Anna Münster on 26.09.22.
6+
//
7+
8+
import UIKit
9+
10+
extension NSLayoutAnchor {
11+
@objc
12+
open func constraint(equalTo anchor: NSLayoutAnchor<AnchorType>, priority: Float) -> NSLayoutConstraint {
13+
let con = constraint(equalTo: anchor)
14+
con.priority = UILayoutPriority(rawValue: priority)
15+
return con
16+
}
17+
18+
@objc
19+
open func constraint(equalTo anchor: NSLayoutAnchor<AnchorType>, constant: CGFloat, priority: Float) -> NSLayoutConstraint {
20+
let con = constraint(equalTo: anchor, constant: constant)
21+
con.priority = UILayoutPriority(rawValue: priority)
22+
return con
23+
}
24+
}
25+
26+
extension NSLayoutDimension {
27+
@objc
28+
open func constraint(equalToConstant constant: CGFloat, priority: Float) -> NSLayoutConstraint {
29+
let con = constraint(equalToConstant: constant)
30+
con.priority = UILayoutPriority(rawValue: priority)
31+
return con
32+
}
33+
34+
open func constraint(equalToOptionalConstant constant: CGFloat?) -> NSLayoutConstraint? {
35+
guard let constant else { return nil }
36+
return constraint(equalToConstant: constant)
37+
}
38+
}

Diff for: Sources/UIKitComponents/Extensions/UIView.swift

+18-68
Original file line numberDiff line numberDiff line change
@@ -40,54 +40,21 @@ public extension UIView {
4040
paddingLeft: CGFloat = 0,
4141
paddingBottom: CGFloat = 0,
4242
paddingRight: CGFloat = 0,
43-
width: CGFloat = 0,
44-
height: CGFloat = 0) {
43+
width: CGFloat? = nil,
44+
height: CGFloat? = nil) {
4545

4646
translatesAutoresizingMaskIntoConstraints = false
4747

48-
if let centerX = centerX {
49-
let centerX = centerXAnchor.constraint(equalTo: centerX, constant: paddingCenterX)
50-
centerX.isActive = true
51-
}
52-
53-
if let centerY = centerY {
54-
let centerY = centerYAnchor.constraint(equalTo: centerY, constant: paddingCenterY)
55-
centerY.isActive = true
56-
}
57-
58-
if let top = top {
59-
let top = topAnchor.constraint(equalTo: top, constant: paddingTop)
60-
top.priority = UILayoutPriority(rawValue: 750)
61-
top.isActive = true
62-
}
63-
64-
if let left = left {
65-
let left = leftAnchor.constraint(equalTo: left, constant: paddingLeft)
66-
left.priority = UILayoutPriority(rawValue: 999)
67-
left.isActive = true
68-
}
69-
70-
if let bottom = bottom {
71-
let bottom = bottomAnchor.constraint(equalTo: bottom, constant: paddingBottom)
72-
bottom.priority = UILayoutPriority(rawValue: 750)
73-
bottom.isActive = true
74-
}
75-
76-
if let right = right {
77-
let right = rightAnchor.constraint(equalTo: right, constant: paddingRight)
78-
right.priority = UILayoutPriority(rawValue: 999)
79-
right.isActive = true
80-
}
81-
82-
if width != 0 {
83-
let width = widthAnchor.constraint(equalToConstant: width)
84-
width.isActive = true
85-
}
86-
87-
if height != 0 {
88-
let height = heightAnchor.constraint(equalToConstant: height)
89-
height.isActive = true
90-
}
48+
NSLayoutConstraint.activate([
49+
centerX?.constraint(equalTo: centerXAnchor, constant: -paddingCenterX),
50+
centerY?.constraint(equalTo: centerYAnchor, constant: -paddingCenterY),
51+
top?.constraint(equalTo: topAnchor, constant: -paddingTop, priority: 750),
52+
left?.constraint(equalTo: leftAnchor, constant: -paddingLeft, priority: 999),
53+
bottom?.constraint(equalTo: bottomAnchor, constant: -paddingBottom, priority: 750),
54+
right?.constraint(equalTo: rightAnchor, constant: -paddingRight, priority: 999),
55+
widthAnchor.constraint(equalToOptionalConstant: width),
56+
heightAnchor.constraint(equalToOptionalConstant: height)
57+
].compactMap { $0 })
9158
}
9259

9360
/**
@@ -105,29 +72,12 @@ public extension UIView {
10572

10673
translatesAutoresizingMaskIntoConstraints = false
10774

108-
if let superviewTopAnchor = superview?.topAnchor {
109-
let top = topAnchor.constraint(equalTo: superviewTopAnchor, constant: paddingTop)
110-
top.priority = UILayoutPriority(rawValue: 750)
111-
top.isActive = true
112-
}
113-
114-
if let superviewLeadingAnchor = superview?.leadingAnchor {
115-
let leading = leadingAnchor.constraint(equalTo: superviewLeadingAnchor, constant: paddingLeft)
116-
leading.priority = UILayoutPriority(rawValue: 999)
117-
leading.isActive = true
118-
}
119-
120-
if let superviewBottomAnchor = superview?.bottomAnchor {
121-
let bottom = bottomAnchor.constraint(equalTo: superviewBottomAnchor, constant: paddingBottom)
122-
bottom.priority = UILayoutPriority(rawValue: 750)
123-
bottom.isActive = true
124-
}
125-
126-
if let superviewTrailingAnchor = superview?.trailingAnchor {
127-
let trailing = trailingAnchor.constraint(equalTo: superviewTrailingAnchor, constant: paddingRight)
128-
trailing.priority = UILayoutPriority(rawValue: 999)
129-
trailing.isActive = true
130-
}
75+
NSLayoutConstraint.activate([
76+
superview?.topAnchor.constraint(equalTo: topAnchor, constant: -paddingTop, priority: 750),
77+
superview?.leadingAnchor.constraint(equalTo: leadingAnchor, constant: -paddingLeft, priority: 999),
78+
superview?.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -paddingBottom, priority: 750),
79+
superview?.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -paddingRight, priority: 999)
80+
].compactMap { $0 })
13181
}
13282

13383
/**

Diff for: UIKitComponentsExample/UIKitComponentsExample/Views/Main/CollectionView/Cells/MainCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MainCell: UICollectionViewCell {
2929

3030
var item: ExampleItem? {
3131
didSet {
32-
guard let item = item else { return }
32+
guard let item else { return }
3333
titleLabel.text = item.title
3434
}
3535
}

Diff for: UIKitComponentsExample/UIKitComponentsExample/Views/Main/CollectionView/MainController+CollectionView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension MainController {
1313
// MARK: - Setup
1414

1515
func setupCollectionView() {
16-
collectionView.register(MainCell.self, forCellWithReuseIdentifier: "cellID")
16+
collectionView.register(MainCell.self, forCellWithReuseIdentifier: MainCell.identifier)
1717

1818
collectionView.backgroundColor = .systemGroupedBackground
1919
collectionView.showsVerticalScrollIndicator = false
@@ -29,7 +29,7 @@ extension MainController {
2929
}
3030

3131
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
32-
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath) as? MainCell else { return UICollectionViewCell() }
32+
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MainCell.identifier, for: indexPath) as? MainCell else { return UICollectionViewCell() }
3333
cell.item = ExampleItem(rawValue: indexPath.item)
3434
return cell
3535
}

0 commit comments

Comments
 (0)