Skip to content

Commit

Permalink
Merge pull request #7 from ustwo/cocoapods-support
Browse files Browse the repository at this point in the history
Added Cocoapods Support.
  • Loading branch information
Daniela Dias committed Oct 6, 2016
2 parents 0367fa1 + 3021446 commit 1ad63ac
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 76 deletions.
1 change: 1 addition & 0 deletions .swift-version
@@ -0,0 +1 @@
3.0
31 changes: 28 additions & 3 deletions README.md
Expand Up @@ -5,21 +5,45 @@

# UIImage+Color.swift

An iOS helper class for creating a UIImage from a UIColor
An iOS helper class for creating a `UIImage` from a `UIColor`.

## Dependencies

* [Xcode](https://itunes.apple.com/gb/app/xcode/id497799835?mt=12#)

## Installation

### CocoaPods

[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:

```bash
$ gem install cocoapods
```

To integrate UIImageColorSwift into your Xcode project using CocoaPods, specify it in your `Podfile`:

```ruby
platform :ios, '8.3'

use_frameworks!

pod 'UIImageColorSwift', '~> 1.0.0'
```

Then, run the following command:

```bash
$ pod install
```

### Manually

* Add the `UIImage+Color.swift` file from the `Sources` folder to your Xcode project.

## Usage

For creating a UIImage from a UIColor
For creating a `UIImage` from a `UIColor`

let image = UIImage.imageFromColor(UIColor.blue)

Expand All @@ -33,7 +57,8 @@ To specify the size of the image:

## Contributing

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See the [Code of Conduct](CODE_OF_CONDUCT) file.
Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms. See the [Code of Conduct](CODE_OF_CONDUCT) file.

## Maintainers

Expand Down
12 changes: 5 additions & 7 deletions Sources/UIImage+Color.swift
Expand Up @@ -32,25 +32,23 @@ extension UIImage {

/**
Creates a UIImage from a UIColor object
- parameter color: The color to create the image from
- parameter width: The width of the image to be created (optional). Default value is 1.0
- parameter height: The height of the image to be created (optional). Default value is 1.0
- returns: A UIImage of that specified color otherwise nil
*/
class func imageFromColor(color: UIColor, width: CGFloat = 1.0, height: CGFloat = 1.0) -> UIImage? {
class func imageFromColor(_ color: UIColor, width: CGFloat = 1.0, height: CGFloat = 1.0) -> UIImage? {

var image: UIImage?

let rect = CGRect(x: 0.0, y : 0.0, width: width, height: height)
let rect = CGRect(x: 0.0, y: 0.0, width: width, height: height)

UIGraphicsBeginImageContext(rect.size)

if let context: CGContextRef = UIGraphicsGetCurrentContext() {
if let context: CGContext = UIGraphicsGetCurrentContext() {

CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
context.setFillColor(color.cgColor)
context.fill(rect)

image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Expand Down
14 changes: 7 additions & 7 deletions UIImageColor.xcodeproj/project.pbxproj
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
65DBC0101DA66A2E003F38F1 /* UIImage+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65DBC00F1DA66A2E003F38F1 /* UIImage+Color.swift */; };
656240B21DA691CC004E2AAF /* UIImage+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656240B11DA691CC004E2AAF /* UIImage+Color.swift */; };
AABC94781C7711E700E4AF13 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AABC94771C7711E700E4AF13 /* AppDelegate.swift */; };
AABC947A1C7711E700E4AF13 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AABC94791C7711E700E4AF13 /* ViewController.swift */; };
AABC947D1C7711E700E4AF13 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AABC947B1C7711E700E4AF13 /* Main.storyboard */; };
Expand All @@ -27,7 +27,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
65DBC00F1DA66A2E003F38F1 /* UIImage+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Color.swift"; sourceTree = "<group>"; };
656240B11DA691CC004E2AAF /* UIImage+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Color.swift"; sourceTree = "<group>"; };
AABC94741C7711E700E4AF13 /* UIImageColor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIImageColor.app; sourceTree = BUILT_PRODUCTS_DIR; };
AABC94771C7711E700E4AF13 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
AABC94791C7711E700E4AF13 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -58,13 +58,13 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
65DBC00E1DA66A2E003F38F1 /* Sources */ = {
656240B01DA691CC004E2AAF /* Sources */ = {
isa = PBXGroup;
children = (
65DBC00F1DA66A2E003F38F1 /* UIImage+Color.swift */,
656240B11DA691CC004E2AAF /* UIImage+Color.swift */,
);
path = Sources;
sourceTree = "<group>";
sourceTree = SOURCE_ROOT;
};
AABC946B1C7711E700E4AF13 = {
isa = PBXGroup;
Expand All @@ -87,7 +87,7 @@
AABC94761C7711E700E4AF13 /* UIImageColor */ = {
isa = PBXGroup;
children = (
65DBC00E1DA66A2E003F38F1 /* Sources */,
656240B01DA691CC004E2AAF /* Sources */,
AABC94771C7711E700E4AF13 /* AppDelegate.swift */,
AABC94791C7711E700E4AF13 /* ViewController.swift */,
AABC947E1C7711E700E4AF13 /* Assets.xcassets */,
Expand Down Expand Up @@ -228,8 +228,8 @@
buildActionMask = 2147483647;
files = (
AABC947A1C7711E700E4AF13 /* ViewController.swift in Sources */,
65DBC0101DA66A2E003F38F1 /* UIImage+Color.swift in Sources */,
AABC94781C7711E700E4AF13 /* AppDelegate.swift in Sources */,
656240B21DA691CC004E2AAF /* UIImage+Color.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
10 changes: 10 additions & 0 deletions UIImageColor/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
59 changes: 0 additions & 59 deletions UIImageColor/Sources/UIImage+Color.swift

This file was deleted.

18 changes: 18 additions & 0 deletions UIImageColorSwift.podspec
@@ -0,0 +1,18 @@
Pod::Spec.new do |spec|
spec.name = 'UIImageColorSwift'
spec.version = '1.0.0'
spec.license = 'MIT'
spec.summary = 'An iOS helper class for creating a UIImage from a UIColor.'
spec.homepage = 'https://github.com/ustwo/image-color-swift'
spec.authors = {
'Shagun Madhikarmi' => 'shagun@ustwo.com',
'Daniela Dias' => 'daniela@ustwo.com'
}
spec.source = {
:git => 'https://github.com/ustwo/image-color-swift.git',
:tag => 'v1.0.0'
}
spec.ios.deployment_target = '8.3'
spec.source_files = 'Sources/*.swift'
spec.requires_arc = true
end

0 comments on commit 1ad63ac

Please sign in to comment.