Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Add docs and make CatalogAssetManager public
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
Sam Rayner committed Sep 4, 2017
1 parent 8d3f318 commit 43855be
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Carthage
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#
# Note: if you ignore the Pods directory, make sure to uncomment
# `pod install` in .travis.yml
#
# Pods/
Example/Pods/
2 changes: 1 addition & 1 deletion ColorAssetCatalog.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'ColorAssetCatalog'
s.version = '0.3.0'
s.version = '0.4.0'
s.summary = 'Adds iOS 9+ compatibility for named colors in asset catalogs.'

# This description is used to generate tags and improve search results.
Expand Down
19 changes: 14 additions & 5 deletions ColorAssetCatalog/Classes/ColorAssetManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
// Created by Sam Rayner on 12/06/2017.
//

class ColorAssetManager {
static let shared = ColorAssetManager()
var catalogName = "Colors"
var cachingEnabled = true
///Provides access to and caching of colors in an asset catalog.
///For general use, use UIColor(asset:) rather than this class.
public class ColorAssetManager {
///The singleton instance to change settings on.
public static let shared = ColorAssetManager()

///The name of the asset catalog to fetch colors from.
public var catalogName = "Colors"

///Whether to cache colors in memory as they are accessed.
public var cachingEnabled = true

var cgColors: [String: CGColor] = [:]

private init() {
NotificationCenter.default.addObserver(self, selector: #selector(clearCache), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
}

@objc func clearCache() {
///Clear all used color objects from memory.
@objc public func clearCache() {
cgColors.removeAll()
}

Expand Down
14 changes: 14 additions & 0 deletions ColorAssetCatalog/Classes/UIColor+ColorAssetCatalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
//

public extension UIColor {
/**
Loads a color from an asset catalog.
On iOS 11 this aliases init(named:).
On iOS 9 or 10 this uses ColorAssetManager.

You can configure the asset catalog to look for colors:

```
ColorAssetManager.shared.catalogName = "MyColors"
```

- Parameter name: The name of the color in the asset catalog.
- Returns: A UIColor or nil if a color is not found of that name.
*/
public convenience init?(asset name: String) {
if #available(iOS 11.0, *) {
self.init(named: name)
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- ColorAssetCatalog (0.3.0)
- ColorAssetCatalog (0.4.0)

DEPENDENCIES:
- ColorAssetCatalog (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ColorAssetCatalog: 9c76c2cc967a38ee13dc05278edf86eedf82484f
ColorAssetCatalog: 1ba2a22174491585f217e4c8cb617221dd4ec8a2

PODFILE CHECKSUM: 89fa1c485c40cfe868239bf0487f00e30a7e49da

Expand Down
8 changes: 4 additions & 4 deletions Example/Pods/Local Podspecs/ColorAssetCatalog.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43855be

Please sign in to comment.