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

Commit fd31d08

Browse files
authored
Merge pull request #3 from hyperlinkgroup/release-1.1
Release 1.1
2 parents 67642a0 + 5d8b6c7 commit fd31d08

15 files changed

+474
-15
lines changed

Diff for: Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "UIKitComponents",
88
platforms: [
9-
.iOS(.v15)
9+
.iOS(.v14)
1010
],
1111
products: [
1212
// Products define the executables and libraries a package produces, and make them visible to other packages.

Diff for: .github/README.md renamed to README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This repository contains basic components for setting up UIKit components progra
44

55
It is made by **[SPACE SQUAD](https://www.spacesquad.de)**! We make great software with ♥️ in Berlin.
66

7-
<img src="assets/README-spacesquad_logo_full.png" width="120">
7+
<img src=".github/assets/README-spacesquad_logo_full.png" width="120">
88

99
---
1010

@@ -39,7 +39,7 @@ This package contains extensions for easily setting up AutoLayout as well as bas
3939

4040

4141
## Screenshots
42-
<img src="assets/README-examples.png" width="300">
42+
<img src=".github/assets/README-examples.png" width="300">
4343

4444

4545
## Installation

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
import UIKit
1010

11-
extension UICollectionViewCell {
12-
public static var identifier: String {
11+
public extension UICollectionViewCell {
12+
static var identifier: String {
1313
String(describing: self)
1414
}
1515
}
1616

17-
extension UITableViewCell {
18-
public static var identifier: String {
17+
public extension UITableViewCell {
18+
static var identifier: String {
1919
String(describing: self)
2020
}
2121
}
22-
extension UITableViewHeaderFooterView {
23-
public static var identifier: String {
22+
public extension UITableViewHeaderFooterView {
23+
static var identifier: String {
2424
String(describing: self)
2525
}
2626
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// NSFetchedResultsController.swift
3+
//
4+
//
5+
// Created by Anna Münster on 19.01.23.
6+
//
7+
8+
import CoreData
9+
10+
public extension NSFetchedResultsController {
11+
/**
12+
Checks if given IndexPath exists in the current controller.
13+
*/
14+
@objc func isValid(indexPath: IndexPath) -> Bool {
15+
if let sections = self.sections,
16+
indexPath.section < sections.count,
17+
indexPath.row < sections[indexPath.section].numberOfObjects {
18+
return true
19+
}
20+
return false
21+
}
22+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension NSLayoutDimension {
3131
return con
3232
}
3333

34-
open func constraint(equalToOptionalConstant constant: CGFloat?) -> NSLayoutConstraint? {
34+
public func constraint(equalToOptionalConstant constant: CGFloat?) -> NSLayoutConstraint? {
3535
guard let constant else { return nil }
3636
return constraint(equalToConstant: constant)
3737
}

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

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// String.swift
3+
//
4+
//
5+
// Created by Anna Münster on 19.01.23.
6+
//
7+
8+
import UIKit
9+
10+
public extension String {
11+
/**
12+
Calculates the height and width based on the number of characters, font and view
13+
14+
- Parameter width: Width of the view containing the text
15+
- Parameter font: Font of the text
16+
17+
- Returns: CGRect containing width and height
18+
*/
19+
func estimateSize(width: CGFloat, font: UIFont) -> CGRect {
20+
let size = CGSize(width: width, height: 10000)
21+
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
22+
23+
return NSString(string: self).boundingRect(with: size, options: options, attributes: [.font: font], context: nil)
24+
}
25+
}
26+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// UICollectionView.swift
3+
//
4+
//
5+
// Created by Anna Münster on 19.01.23.
6+
//
7+
8+
import UIKit
9+
10+
public extension UICollectionView {
11+
/**
12+
Checks if given IndexPath exists in the current controller.
13+
*/
14+
func isValid(indexPath: IndexPath) -> Bool {
15+
indexPath.section < numberOfSections && indexPath.row < numberOfItems(inSection: indexPath.section)
16+
}
17+
}
18+

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

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// UIColor.swift
3+
//
4+
//
5+
// Created by Malte Schoppe on 25.08.21.
6+
//
7+
8+
import UIKit
9+
import SwiftUI
10+
11+
struct ColorComponents {
12+
var r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat
13+
}
14+
15+
extension UIColor {
16+
17+
func getComponents() -> ColorComponents? {
18+
19+
guard let components = cgColor.components else { return nil }
20+
21+
return cgColor.numberOfComponents == 2 ? ColorComponents(r:components[0], g:components[0], b:components[0], a:components[1]) : ColorComponents(r:components[0], g:components[1], b:components[2], a:components[3])
22+
}
23+
24+
public func interpolateRGBColorTo(fraction: CGFloat) -> UIColor {
25+
26+
guard let c1 = self.getComponents(), let c2 = UIColor.green.getComponents() else { return .gray }
27+
28+
var multiplier = max(0, fraction)
29+
multiplier = min(1, fraction)
30+
31+
let red = c1.r + (c2.r - c1.r) * multiplier
32+
let green = c1.g + (c2.g - c1.g) * multiplier
33+
let blue = c1.b + (c2.b - c1.b) * multiplier
34+
let alpha = c1.a + (c2.a - c1.a) * multiplier
35+
36+
return UIColor.init(red: red, green: green, blue: blue, alpha: alpha)
37+
}
38+
39+
}
40+
41+
extension UIColor {
42+
public convenience init(hexString: String) {
43+
let hex = "#\(hexString)".trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
44+
var int = UInt64()
45+
46+
Scanner(string: hex).scanHexInt64(&int)
47+
48+
let a, r, g, b: UInt64
49+
50+
switch hex.count {
51+
case 3: // RGB (12-bit)
52+
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
53+
case 6: // RGB (24-bit)
54+
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
55+
case 8: // ARGB (32-bit)
56+
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
57+
default:
58+
(a, r, g, b) = (255, 0, 0, 0)
59+
}
60+
61+
self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
62+
}
63+
64+
var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
65+
var red: CGFloat = 0
66+
var green: CGFloat = 0
67+
var blue: CGFloat = 0
68+
var alpha: CGFloat = 0
69+
70+
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
71+
72+
return (red, green, blue, alpha)
73+
}
74+
}
75+
76+
extension Color {
77+
public init(uiColor: UIColor) {
78+
self.init(red: Double(uiColor.rgba.red), green: Double(uiColor.rgba.green), blue: Double(uiColor.rgba.blue), opacity: Double(uiColor.rgba.alpha))
79+
}
80+
}

0 commit comments

Comments
 (0)