HexColor
//
// HexColor.swift
// HexColor
//
// Created by Tuomas Artman on 1.9.2014.
// Copyright (c) 2014 Tuomas Artman. All rights reserved.
// import Foundation
import UIKit extension UIColor { /// Initializes UIColor with an integer.
///
/// - parameter value: The integer value of the color. E.g. 0xFF0000 is red, 0x0000FF is blue.
public convenience init(_ value: Int) {
let components = getColorComponents(value)
self.init(red: components.red, green: components.green, blue: components.blue, alpha: 1.0)
} /// Initializes UIColor with an integer and alpha value.
///
/// - parameter value: The integer value of the color. E.g. 0xFF0000 is red, 0x0000FF is blue.
/// - parameter alpha: The alpha value.
public convenience init(_ value: Int, alpha: CGFloat) {
let components = getColorComponents(value)
self.init(red: components.red, green: components.green, blue: components.blue, alpha: alpha)
} /// Creates a new color with the given alpha value
///
/// For example, (0xFF0000).alpha(0.5) defines a red color with 50% opacity.
///
/// - returns: A UIColor representation of the Int with the given alpha value
public func alpha(value:CGFloat) -> UIKit.UIColor {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0 self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) return UIKit.UIColor(red: red, green: green, blue: blue, alpha: value)
} /// Mixes the color with another color
///
/// - parameter color: The color to mix with
/// - parameter amount: The amount (0-1) to mix the new color in.
/// - returns: A new UIColor instance representing the resulting color
public func mixWithColor(color:UIColor, amount:Float) -> UIColor {
var comp1: [CGFloat] = Array(count: 4, repeatedValue: 0);
self.getRed(&comp1[0], green: &comp1[1], blue: &comp1[2], alpha: &comp1[3]) var comp2: [CGFloat] = Array(count: 4, repeatedValue: 0);
color.getRed(&comp2[0], green: &comp2[1], blue: &comp2[2], alpha: &comp2[3]) var comp: [CGFloat] = Array(count: 4, repeatedValue: 0);
for i in 0...3 {
comp[i] = comp1[i] + (comp2[i] - comp1[i]) * CGFloat(amount)
} return UIColor(red:comp[0], green: comp[1], blue: comp[2], alpha: comp[3])
}
} private func getColorComponents(value: Int) -> (red: CGFloat, green: CGFloat, blue: CGFloat) {
let r = CGFloat(value >> 16 & 0xFF) / 255.0
let g = CGFloat(value >> 8 & 0xFF) / 255.0
let b = CGFloat(value & 0xFF) / 255.0 return (r, g, b)
}
github地址:https://github.com/artman/HexColor
HexColor的更多相关文章
- 【blade利刃出鞘】一起进入移动端webapp开发吧
前言 在移动浪潮袭来的时候,小钗有幸进入框架组做webapp框架开发,过程中遇到了移动端的各种坑,也产生了各种激情,就我们公司的发展历程来说 第一阶段:使用传统方式开发移动站点,少量引入HTML5元素 ...
- UITabBarController 基本定制
UITabBarController 定制 特点 用法 1.准备好你的tabBar图片及其他图片(哈哈哈!!!!),我的图片都放在了Assets.xcassets中. 2.导入本工程中的Categro ...
- IOS开发基础知识--碎片49
1:iOS项目配置文件info.plist文件解析 Localization native development region本地化 Executable file可执行文件路径 Bundle id ...
- jquery颜色选择器
本站下载 第二种:纯JAVASCRIPT: <html> <head> <meta http-equiv="Content-Type" content ...
- IOS开发基础知识--碎片37
1:iOS 使用NJKWebViewProgress做webview进度条 引入头文件: #import "NJKWebViewProgressView.h" #import &q ...
- jQuery Colorpicker Spectrum api 中文 文档 属性 事件 方法
jQuery Colorpicker Spectrum 所需的CSS和JavaScript文件: <script src='spectrum.js'></script> < ...
- iOS根据16进制的色号来设置颜色,适合封装工具类
iOS中有时候UI给的一个色号就像 #54e1b7 这个,而我们一般设置颜色都是根据RBG来设置的,所以这里需要把这个16进制的色号转为RGB值,这里我们就使用一下的方法来调用设置颜色. + (UIC ...
- iOS 多快好省的宏定义
http://my.oschina.net/yongbin45/blog/150149 // 字符串:#ifndef nilToEmpty#define nilToEmpty(object) (obj ...
- TweenMax参数说明
TweenMax 建立在 TweenLite 和 TweenFilterLite 基础之上,因此,又揉合了这二者的功能,使得功能更加的齐备,但是如果说易用性,觉得还是 TweenLite 来得方便一些 ...
随机推荐
- mac下显示隐藏文件
一.在终端中 ls -a就可以查看隐藏文件. 显示和隐藏的命令例如以下: 显示:defaults write com.apple.finder AppleShowAllFiles -bool true ...
- map的类型映射
以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题. 以下是C++源码,比较简短,容易理解的. #include " ...
- 自定义带弹性效果的pageControl
分三部分实现,在drawrect方法里画出灰色背景,根据pageCount创建对应个数的dotView放置在对应位置,并隐藏,创建一个CAShapeView类型的layer,根据scrollView的 ...
- iOS系统相册的有关操作
iOS中,我们选择相册中的资源和调用摄像头可以使用 :UIImagePickerController类来完成,不使用UI我们可以通过:ALAssetsLibrary类来使用相册资源. 一. ALAss ...
- calc()函数的使用
calc()函数算是css中的一个另类了,一般来说css都是直接确定的样式,而calc()函数却是可以动态计算,这和css静态的概念有些区别,但这并不妨碍其优秀的性能. 什么是calc()? calc ...
- .C .h 和 .CCP的区别
1.*.H:C语言规定使用一个变量或调用一个函数前必须声明,为了使用方便,经常把常用函数,例如Windows API的函数,MFC类写入头文件.h,这样每次需要引用时只要使用#include加入就可以 ...
- C++之类和对象——C++ primer plus学习(一)
一.类的构造函数和析构函数 1.构造函数: 1)试图将类成员名称用作构造函数的参数名是错误的. 2)构造函数的参数表示的不是类成员, 而是赋给类成员的值. 3)为了避免这种混乱,一种 ...
- (原)Ubuntu16中卸载并重新安装google的Protocol Buffers
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5782992.html 目前最新的是1.6.1 1. 卸载掉老版本的Protocol: sudo apt ...
- [Head First Python]3. 文件与异常:处理错误
datafile.txt Man: Is this the right room for an argument? Other Man: I've told you once. Man: No you ...
- Fatal error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY' in D:\inetpub\vhosts\zenpty.com\httpdocs\includes\database
打开php.ini配置文件,找到php_pdo_mysql.dll,如果前面有分号";"则表示该行被注释掉了,将分号去掉,保存,然后重启apache服务,重新访问页面,问题解决了.