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

Commit e259060

Browse files
authored
Merge pull request #52 from jathu/rename-struct
Rename struct
2 parents 1314db3 + 7ec0ed7 commit e259060

File tree

7 files changed

+59
-53
lines changed

7 files changed

+59
-53
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Asynchronous example:
1414
let image = UIImage(named: "yeezus.png")
1515

1616
image.getColors { colors in
17-
backgroundView.backgroundColor = colors.backgroundColor
18-
mainLabel.textColor = colors.primaryColor
19-
secondaryLabel.textColor = colors.secondaryColor
20-
detailLabel.textColor = colors.detailColor
17+
backgroundView.backgroundColor = colors.background
18+
mainLabel.textColor = colors.primary
19+
secondaryLabel.textColor = colors.secondary
20+
detailLabel.textColor = colors.detail
2121
}
2222
```
2323

@@ -26,10 +26,10 @@ Synchronous example:
2626
```swift
2727
let colors = UIImage(named: "yeezus.png").getColors()
2828

29-
backgroundView.backgroundColor = colors.backgroundColor
30-
mainLabel.textColor = colors.primaryColor
31-
secondaryLabel.textColor = colors.secondaryColor
32-
detailLabel.textColor = colors.detailColor
29+
backgroundView.backgroundColor = colors.background
30+
mainLabel.textColor = colors.primary
31+
secondaryLabel.textColor = colors.secondary
32+
detailLabel.textColor = colors.detail
3333
```
3434

3535
## UIImage Methods
@@ -58,17 +58,23 @@ getColors(scaleDownSize: CGSize, completionHandler: (UIImageColors) -> Void) ->
5858

5959
Passes a `UIImageColors` object into the closure, with a custom image rescale. Use smaller sizes for better performance at the cost of quality colors. Use larger sizes for better color sampling and quality at the cost of performance. This runs on the background thread.
6060

61-
## UIImageColors
61+
## UIImageColors Object
6262

63-
`UIImageColors` is struct that contains four different `UIColor`s.
63+
`UIImageColors` is struct that contains four different `UIColor` variables.
6464

6565
```swift
66-
var backgroundColor
67-
var primaryColor
68-
var secondaryColor
69-
var detailColor
66+
public struct UIImageColors {
67+
public var background: UIColor!
68+
public var primary: UIColor!
69+
public var secondary: UIColor!
70+
public var detail: UIColor!
71+
}
7072
```
7173

74+
## Installation
75+
76+
You can either directly copy [UIImageColors.swift](sources/UIImageColors.swift) into your project *or* you can use CocoaPods: [UIImageColors](https://cocoapods.org/pods/UIImageColors).
77+
7278
## License
7379

7480
The [license](https://github.com/jathu/UIImageColors/blob/master/LICENSE) is provided in the project folder. Please also refer to Panic's [original license](https://github.com/panicinc/ColorArt/#license).

Sources/UIImageColors.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import UIKit
1010

1111
public struct UIImageColors {
12-
public var backgroundColor: UIColor!
13-
public var primaryColor: UIColor!
14-
public var secondaryColor: UIColor!
15-
public var detailColor: UIColor!
12+
public var background: UIColor!
13+
public var primary: UIColor!
14+
public var secondary: UIColor!
15+
public var detail: UIColor!
1616
}
1717

1818
class PCCountedColor {
@@ -219,13 +219,13 @@ extension UIImage {
219219
}
220220
}
221221
}
222-
result.backgroundColor = proposedEdgeColor.color
222+
result.background = proposedEdgeColor.color
223223

224224
// Get foreground colors
225225
enumerator = imageColors.objectEnumerator()
226226
sortedColors.removeAllObjects()
227227
sortedColors = NSMutableArray(capacity: imageColors.count)
228-
let findDarkTextColor = !result.backgroundColor.isDarkColor
228+
let findDarkTextColor = !result.background.isDarkColor
229229

230230
while var kolor = enumerator.nextObject() as? UIColor {
231231
kolor = kolor.colorWithMinimumSaturation(minSaturation: 0.15)
@@ -239,38 +239,38 @@ extension UIImage {
239239
for curContainer in sortedColors {
240240
let kolor = (curContainer as! PCCountedColor).color
241241

242-
if result.primaryColor == nil {
243-
if kolor.isContrastingColor(compareColor: result.backgroundColor) {
244-
result.primaryColor = kolor
242+
if result.primary == nil {
243+
if kolor.isContrastingColor(compareColor: result.background) {
244+
result.primary = kolor
245245
}
246-
} else if result.secondaryColor == nil {
247-
if !result.primaryColor.isDistinct(compareColor: kolor) || !kolor.isContrastingColor(compareColor: result.backgroundColor) {
246+
} else if result.secondary == nil {
247+
if !result.primary.isDistinct(compareColor: kolor) || !kolor.isContrastingColor(compareColor: result.background) {
248248
continue
249249
}
250250

251-
result.secondaryColor = kolor
252-
} else if result.detailColor == nil {
253-
if !result.secondaryColor.isDistinct(compareColor: kolor) || !result.primaryColor.isDistinct(compareColor: kolor) || !kolor.isContrastingColor(compareColor: result.backgroundColor) {
251+
result.secondary = kolor
252+
} else if result.detail == nil {
253+
if !result.secondary.isDistinct(compareColor: kolor) || !result.primary.isDistinct(compareColor: kolor) || !kolor.isContrastingColor(compareColor: result.background) {
254254
continue
255255
}
256256

257-
result.detailColor = kolor
257+
result.detail = kolor
258258
break
259259
}
260260
}
261261

262-
let isDarkBackgound = result.backgroundColor.isDarkColor
262+
let isDarkBackgound = result.background.isDarkColor
263263

264-
if result.primaryColor == nil {
265-
result.primaryColor = isDarkBackgound ? whiteColor:blackColor
264+
if result.primary == nil {
265+
result.primary = isDarkBackgound ? whiteColor:blackColor
266266
}
267267

268-
if result.secondaryColor == nil {
269-
result.secondaryColor = isDarkBackgound ? whiteColor:blackColor
268+
if result.secondary == nil {
269+
result.secondary = isDarkBackgound ? whiteColor:blackColor
270270
}
271271

272-
if result.detailColor == nil {
273-
result.detailColor = isDarkBackgound ? whiteColor:blackColor
272+
if result.detail == nil {
273+
result.detail = isDarkBackgound ? whiteColor:blackColor
274274
}
275275

276276
return result

Supporting Files/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.3.0</string>
18+
<string>1.4.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

UIImageColors.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "UIImageColors"
3-
spec.version = "1.3.1"
3+
spec.version = "1.4.0"
44
spec.license = "MIT"
55
spec.summary = "iTunes style color fetcher for UIImage."
66
spec.homepage = "https://github.com/jathu/UIImageColors"

UIImageColorsPlayground.playground/Contents.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ func makeBox(_ asynchronous: Bool, completionHandler: @escaping (UIView) -> Void
3333

3434
if asynchronous {
3535
c.albumImageView.image!.getColors { colors in
36-
c.backgroundColor = colors.backgroundColor
37-
c.albumTitle.textColor = colors.primaryColor
38-
c.artistTitle.textColor = colors.secondaryColor
39-
c.yearLabel.textColor = colors.detailColor
36+
c.backgroundColor = colors.background
37+
c.albumTitle.textColor = colors.primary
38+
c.artistTitle.textColor = colors.secondary
39+
c.yearLabel.textColor = colors.detail
4040
if i == maxIterations-1 {
4141
completionHandler(box)
4242
}
4343
}
4444
} else {
4545
let colors = c.albumImageView.image!.getColors()
46-
c.backgroundColor = colors.backgroundColor
47-
c.albumTitle.textColor = colors.primaryColor
48-
c.artistTitle.textColor = colors.secondaryColor
49-
c.yearLabel.textColor = colors.detailColor
46+
c.backgroundColor = colors.background
47+
c.albumTitle.textColor = colors.primary
48+
c.artistTitle.textColor = colors.secondary
49+
c.yearLabel.textColor = colors.detail
5050
if i == maxIterations-1 {
5151
completionHandler(box)
5252
}

UIImageColorsPlayground.playground/timeline.xctimeline

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
version = "3.0">
44
<TimelineItems>
55
<LoggerValueHistoryTimelineItem
6-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=23&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=515104523.006536"
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=23&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=518703781.904105"
77
selectedRepresentationIndex = "0"
88
shouldTrackSuperviewWidth = "NO">
99
</LoggerValueHistoryTimelineItem>
1010
<LoggerValueHistoryTimelineItem
11-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=20&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=515104523.00672"
11+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=20&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=518703781.9045"
1212
selectedRepresentationIndex = "0"
1313
shouldTrackSuperviewWidth = "NO">
1414
</LoggerValueHistoryTimelineItem>
1515
<LoggerValueHistoryTimelineItem
16-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=19&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=515104523.00685"
16+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=19&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=518703781.904713"
1717
selectedRepresentationIndex = "0"
1818
shouldTrackSuperviewWidth = "NO">
1919
</LoggerValueHistoryTimelineItem>
2020
<LoggerValueHistoryTimelineItem
21-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=22&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=515104523.006985"
21+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=22&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=518703781.904925"
2222
selectedRepresentationIndex = "0"
2323
shouldTrackSuperviewWidth = "NO">
2424
</LoggerValueHistoryTimelineItem>
2525
<LoggerValueHistoryTimelineItem
26-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=3&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=515104523.007109"
26+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=3&amp;EndingLineNumber=59&amp;StartingColumnNumber=1&amp;StartingLineNumber=59&amp;Timestamp=518703781.90513"
2727
selectedRepresentationIndex = "0"
2828
shouldTrackSuperviewWidth = "NO">
2929
</LoggerValueHistoryTimelineItem>
3030
<LoggerValueHistoryTimelineItem
31-
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2917&amp;EndingColumnNumber=8&amp;EndingLineNumber=59&amp;StartingColumnNumber=5&amp;StartingLineNumber=59&amp;Timestamp=515104523.007231"
31+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=2877&amp;EndingColumnNumber=8&amp;EndingLineNumber=59&amp;StartingColumnNumber=5&amp;StartingLineNumber=59&amp;Timestamp=518703781.905348"
3232
selectedRepresentationIndex = "0"
3333
shouldTrackSuperviewWidth = "NO">
3434
</LoggerValueHistoryTimelineItem>
3535
<LoggerValueHistoryTimelineItem
36-
documentLocation = "#CharacterRangeLen=3&amp;CharacterRangeLoc=2913&amp;EndingColumnNumber=8&amp;EndingLineNumber=58&amp;StartingColumnNumber=5&amp;StartingLineNumber=58&amp;Timestamp=515104523.007466"
36+
documentLocation = "#CharacterRangeLen=3&amp;CharacterRangeLoc=2873&amp;EndingColumnNumber=8&amp;EndingLineNumber=58&amp;StartingColumnNumber=5&amp;StartingLineNumber=58&amp;Timestamp=518703781.905768"
3737
lockedSize = "{546, 444}"
3838
selectedRepresentationIndex = "0"
3939
shouldTrackSuperviewWidth = "NO">

preview.png

167 KB
Loading

0 commit comments

Comments
 (0)