[ADDØ Shade color method

This commit is contained in:
Yannick Loriot 2015-06-06 17:38:49 +02:00
parent 62e2b7b7c3
commit 43053c3526
5 changed files with 31 additions and 3 deletions

View File

@ -7,7 +7,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'https://twitter.com/yannickloriot'
s.authors = { 'Yannick Loriot' => 'contact@yannickloriot.com' }
s.source = { :git => 'https://github.com/yannickl/DynamicColor.git', :tag => s.version }
s.screenshot = 'http://yannickloriot.com/resources/dynamiccolor-screenshot.png'
s.screenshot = 'http://yannickloriot.com/resources/dynamiccolor-sample-screenshot.png'
s.ios.deployment_target = '8.0'

View File

@ -309,4 +309,15 @@ public extension UIColor {
public func tintColor(amount: CGFloat = 0.2) -> UIColor {
return mixWithColor(UIColor.whiteColor(), weight: amount)
}
/**
Creates and return a color object corresponding to the mix of the receiver and an amount of black color, which reduces lightness.
:params: amount Float between 0 and 1. The default amount is equal to 0.2.
:returns: A darker UIColor.
*/
public func shadeColor(amount: CGFloat = 0.2) -> UIColor {
return mixWithColor(UIColor.blackColor(), weight: amount)
}
}

View File

@ -65,6 +65,9 @@ class ViewController: UIViewController, UICollectionViewDataSource {
let tintColor = ("Tint", mainColor.tintColor())
_colors.append(tintColor)
let shadeColor = ("Shade", mainColor.shadeColor())
_colors.append(shadeColor)
colors = _colors
}

View File

@ -5,7 +5,7 @@
DynamicColor provides powerfull methods to manipulate colors in an easy way.
<p align="center">
<img src="http://yannickloriot.com/resources/dynamiccolor-screenshot.png" alt="example screenshot" width="300" />
<img src="http://yannickloriot.com/resources/dynamiccolor-sample-screenshot.png" alt="example screenshot" width="300" />
</p>
## Usage

View File

@ -189,7 +189,7 @@ class DynamicColorTests: XCTestCase {
}
func testTintColor() {
let tint = UIColor(hex: 0xc0392b).tintColor()
let tint = UIColor(hex: 0xc0392b).tintColor()
XCTAssert(tint.isEqualToHexString("#cc6055"), "Color string should equal to #cc6055")
@ -201,4 +201,18 @@ class DynamicColorTests: XCTestCase {
XCTAssert(alwaysWhite.isEqualToHexString("#ffffff"), "Color string should equal to #ffffff")
}
func testShadeColor() {
let shade = UIColor(hex: 0xc0392b).shadeColor()
XCTAssert(shade.isEqualToHexString("#992d22"), "Color string should equal to #992d22")
let black = UIColor(hex: 0xc0392b).shadeColor(amount: 1)
XCTAssert(black.isEqualToHexString("#000000"), "Color string should equal to #000000")
let alwaysBlack = UIColor.blackColor().shadeColor()
XCTAssert(alwaysBlack.isEqualToHexString("#000000"), "Color string should equal to #000000")
}
}