[ADDØ Shade color method
This commit is contained in:
parent
62e2b7b7c3
commit
43053c3526
|
@ -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'
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue