Skip to content

Commit edc1e7d

Browse files
author
ApptekStudios
committed
Add SwiftUI support for Image, Color, Font
1 parent 4a09ece commit edc1e7d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// SwiftUI.Color+ColorResource.swift
3+
// R.swift Library
4+
//
5+
// Created by Tobeas Brennan on 30-11-19.
6+
// From: https://github.com/mac-cain13/R.swift.Library
7+
// License: MIT License
8+
//
9+
10+
import SwiftUI
11+
12+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
13+
public extension SwiftUI.Color {
14+
/**
15+
Returns the SwiftUI.Color from this resource (R.color.*)
16+
17+
- parameter resource: The resource you want the image of (R.color.*)
18+
19+
- returns: A SwiftUI.Color for the given resource (R.color.*)
20+
*/
21+
init(_ resource: ColorResourceType) {
22+
self.init(resource.name, bundle: resource.bundle)
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// SwiftUI.Font+FontResource.swift
3+
// R.swift Library
4+
//
5+
// Created by Tobeas Brennan on 30-11-19.
6+
// From: https://github.com/mac-cain13/R.swift.Library
7+
// License: MIT License
8+
//
9+
10+
import SwiftUI
11+
12+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
13+
public extension SwiftUI.Font {
14+
/**
15+
Creates and returns a SwiftUI.Font for the specified font resource (R.font.*) and size.
16+
17+
- parameter resource: The font resource (R.font.*) for the specific font to load
18+
- parameter size: The size (in points) to which the font is scaled. This value must be greater than 0.0.
19+
20+
- returns: A SwiftUI.Font object of the specified font resource and size.
21+
*/
22+
init(_ resource: FontResourceType, size: CGFloat) {
23+
self = .custom(resource.fontName, size: size)
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// SwiftUI.Image+ImageResource.swift
3+
// R.swift Library
4+
//
5+
// Created by Tobeas Brennan on 30-11-19.
6+
// From: https://github.com/mac-cain13/R.swift.Library
7+
// License: MIT License
8+
//
9+
10+
import SwiftUI
11+
12+
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
13+
public extension SwiftUI.Image {
14+
/**
15+
Returns the image from this resource (R.image.*)
16+
17+
- parameter resource: The resource you want the image of (R.image.*)
18+
19+
- returns: A SwiftUI.Image for the given resource (R.image.*)
20+
*/
21+
init(_ resource: ImageResourceType) {
22+
self.init(resource.name, bundle: resource.bundle)
23+
}
24+
}

0 commit comments

Comments
 (0)