iOS --- UI系列之UIColoer

开发中颜色如何表示

颜色是一个App很重要的内容。在iOS中颜色有几种表现形式:6位16进制、颜色关键字、RGB
附带一个RGB颜色查询对照表(6位16进制)http://www.114la.com/other/rgb.htm


这里是常用的颜色的方法取自UIColoer类中


+ (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
//指定HSB,参数是:色调(hue),饱和的(saturation),亮度(brightness)
+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
//指定RGB,参数是:红、绿、黄、透明度,范围是0-1
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
//将一个CGColoer转换为一个UIColoer
+ (UIColor *)colorWithCGColor:(CGColorRef)cgColor;
//
+ (UIColor *)colorWithPatternImage:(UIImage *)image;
//
+ @property(class, nonatomic, readonly) UIColor *blackColor;      // 0.0 white
@property(class, nonatomic, readonly) UIColor *darkGrayColor;   // 0.333 white
@property(class, nonatomic, readonly) UIColor *lightGrayColor;  // 0.667 white
@property(class, nonatomic, readonly) UIColor *whiteColor;      // 1.0 white
@property(class, nonatomic, readonly) UIColor *grayColor;       // 0.5 white
@property(class, nonatomic, readonly) UIColor *redColor;        // 1.0, 0.0, 0.0 RGB
@property(class, nonatomic, readonly) UIColor *greenColor;      // 0.0, 1.0, 0.0 RGB
@property(class, nonatomic, readonly) UIColor *blueColor;       // 0.0, 0.0, 1.0 RGB
@property(class, nonatomic, readonly) UIColor *cyanColor;       // 0.0, 1.0, 1.0 RGB
@property(class, nonatomic, readonly) UIColor *yellowColor;     // 1.0, 1.0, 0.0 RGB
@property(class, nonatomic, readonly) UIColor *magentaColor;    // 1.0, 0.0, 1.0 RGB
@property(class, nonatomic, readonly) UIColor *orangeColor;     // 1.0, 0.5, 0.0 RGB
@property(class, nonatomic, readonly) UIColor *purpleColor;     // 0.5, 0.0, 0.5 RGB
@property(class, nonatomic, readonly) UIColor *brownColor;      // 0.6, 0.4, 0.2 RGB
@property(class, nonatomic, readonly) UIColor *clearColor;      // 0.0 white, 0.0 alpha
#else
+ (UIColor *)blackColor;      // 0.0 white
+ (UIColor *)darkGrayColor;   // 0.333 white 
+ (UIColor *)lightGrayColor;  // 0.667 white 
+ (UIColor *)whiteColor;      // 1.0 white 
+ (UIColor *)grayColor;       // 0.5 white 
+ (UIColor *)redColor;        // 1.0, 0.0, 0.0 RGB 
+ (UIColor *)greenColor;      // 0.0, 1.0, 0.0 RGB 
+ (UIColor *)blueColor;       // 0.0, 0.0, 1.0 RGB 
+ (UIColor *)cyanColor;       // 0.0, 1.0, 1.0 RGB 
+ (UIColor *)yellowColor;     // 1.0, 1.0, 0.0 RGB 
+ (UIColor *)magentaColor;    // 1.0, 0.0, 1.0 RGB 
+ (UIColor *)orangeColor;     // 1.0, 0.5, 0.0 RGB 
+ (UIColor *)purpleColor;     // 0.5, 0.0, 0.5 RGB 
+ (UIColor *)brownColor;      // 0.6, 0.4, 0.2 RGB 
+ (UIColor *)clearColor;      // 0.0 white, 0.0 alpha 

这里给出一个转换16位颜色的方法

#defineUIColorFromHex(s)  [UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0green:(((s &0xFF00) >>8))/255.0blue:((s &0xFF))/255.0alpha:1.0]
self.view.backgroundColor=UIColorFromHex(0xdcdcdc);

添加一个背景图给UIView

如果想要为UIView添加一张背景图,常用的方式有两种:

第一种, 是在UIView上加载一UIImageView(在UIImageView添加背景图);

第二种, 是调用UIColor 的initWithPatternImage方法,具体做法:

UIColor *coloer = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:ImageName]];
    self.view.backgroundColor = coloer;

但是第二种方法网上说有弊端,很占内存,大约比第一种方法多占6M左右而且还不会自动释放。


CGColoer UIColoer CIColoer

这里就不过多的解释了,这里有一篇文章写的很全面http://www.awnlab.com/archives/2666.html


渐变颜色如何做

可以参考一下这篇博客写的很全面很好http://www.jianshu.com/p/3e0e25fd9b85

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值