Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 42119d2

Browse files
committed
Add ColorResource
1 parent a029cf8 commit 42119d2

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Library/Core/ColorResource.swift

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// ColorResource.swift
3+
// R.swift.Library
4+
//
5+
// Created by Tom Lokhorst on 2016-03-13.
6+
// Copyright © 2016 Mathijs Kadijk. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public protocol ColorResourceType {
12+
13+
/// Name of the color
14+
var name: String { get }
15+
16+
/// Red componenent of color
17+
var red: CGFloat { get }
18+
19+
/// Green componenent of color
20+
var green: CGFloat { get }
21+
22+
/// Blue componenent of color
23+
var blue: CGFloat { get }
24+
25+
/// Alpha componenent of color
26+
var alpha: CGFloat { get }
27+
}
28+
29+
public extension ColorResourceType {
30+
/**
31+
Returns the a UIColor
32+
33+
- returns: A UIColor for this color resource
34+
*/
35+
func color() -> UIColor {
36+
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
37+
}
38+
}
39+
40+
public struct ColorResource: ColorResourceType {
41+
42+
/// Name of the color
43+
public let name: String
44+
45+
/// Red componenent of color
46+
public let red: CGFloat
47+
48+
/// Green componenent of color
49+
public let green: CGFloat
50+
51+
/// Blue componenent of color
52+
public let blue: CGFloat
53+
54+
/// Alpha componenent of color
55+
public let alpha: CGFloat
56+
57+
public init(name: String, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
58+
self.name = name
59+
self.red = red
60+
self.green = green
61+
self.blue = blue
62+
self.alpha = alpha
63+
}
64+
}

R.swift.Library.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
D5E435A91C3CFB460091090C /* NibResource+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E435A81C3CFB460091090C /* NibResource+UIKit.swift */; };
6262
D5E435AD1C3D00770091090C /* FileResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E435AC1C3D00770091090C /* FileResource.swift */; };
6363
E20F34A71C92B44100338F81 /* NSData+FileResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = E20F34A61C92B44100338F81 /* NSData+FileResource.swift */; };
64+
E22D43671C95EEA100692FFF /* ColorResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = E22D43661C95EEA100692FFF /* ColorResource.swift */; };
6465
/* End PBXBuildFile section */
6566

6667
/* Begin PBXContainerItemProxy section */
@@ -113,6 +114,7 @@
113114
D5E435A81C3CFB460091090C /* NibResource+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NibResource+UIKit.swift"; sourceTree = "<group>"; };
114115
D5E435AC1C3D00770091090C /* FileResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileResource.swift; sourceTree = "<group>"; };
115116
E20F34A61C92B44100338F81 /* NSData+FileResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSData+FileResource.swift"; sourceTree = "<group>"; };
117+
E22D43661C95EEA100692FFF /* ColorResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorResource.swift; sourceTree = "<group>"; };
116118
/* End PBXFileReference section */
117119

118120
/* Begin PBXFrameworksBuildPhase section */
@@ -171,6 +173,7 @@
171173
D543F9CD1C1499CF00D16A0C /* Core */ = {
172174
isa = PBXGroup;
173175
children = (
176+
E22D43661C95EEA100692FFF /* ColorResource.swift */,
174177
D5E435AC1C3D00770091090C /* FileResource.swift */,
175178
D57E1EB21C3D762300DDA68F /* FontResource.swift */,
176179
D543F9BA1C1497EB00D16A0C /* Identifier.swift */,
@@ -463,6 +466,7 @@
463466
D57E1EB51C3D774000DDA68F /* UIFont+FontResource.swift in Sources */,
464467
D5588CAB1C3F9DBE00912F97 /* UINib+NibResource.swift in Sources */,
465468
D553F5871C44170E00885232 /* UIImage+ImageResource.swift in Sources */,
469+
E22D43671C95EEA100692FFF /* ColorResource.swift in Sources */,
466470
D51335271C959DF20014C9D4 /* StoryboardViewControllerResource.swift in Sources */,
467471
D543F9C61C14992000D16A0C /* UICollectionView+ReuseIdentifierProtocol.swift in Sources */,
468472
D543F9BF1C14983100D16A0C /* StoryboardSegueIdentifierProtocol.swift in Sources */,

0 commit comments

Comments
 (0)