IOS疯狂基础之UIColor
2013-02-24 18:19
501 查看
UIColor常见用法,废话少说 直接网上抄来记录下,凭空想还真有点想不起来,最近记忆力不好,所以记着点。
UIColor *myWhiteTransparentColor = [ UIColor colorWithWhite: 1.0 alpha: 0.50 ];
UIColor *myColorHue = [ UIColor colorWithHue: 120.0 / 360.0
saturation: 0.75
brightness: 0.50
alpha: 1.0
];
UIColor *myColorRGB = [ UIColor colorWithRed: 0.75
green: 1.0
blue: 0.75
alpha: 1.0
];
如果你打算重用许多不同的UIColor对象,你也可以创建它们的实例:
UIColor *myWhiteTransparentColor = [ [ UIColor alloc ]
initWithWhite: 1.0 alpha: 0.50
];
UIColor *myColorHue = [ [ UIColor alloc ]
initWithHue: 120.0 / 360.0
saturation: 0.75
brightness: 0.50
alpha: 1.0
];
UIColor *myColorRGB = [ [ UIColor alloc ] initWithRed: 0.75
green: 1.0
blue: 0.75
alpha: 1.0
];
UIColor类还支持许多静态方法,可以创建系统颜色,这些颜色都经过iPhone的校正,以达到尽可能准确的地步。这些方法如下所示,均来自UIColor.h:
+ (UIColor *)blackColor; // 0.0 白色
+ (UIColor *)darkGrayColor; // 0.333 白色
+ (UIColor *)lightGrayColor; // 0.667 白色
+ (UIColor *)whiteColor; // 1.0 白色
+ (UIColor *)grayColor; // 0.5 白色
+ (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 白色, 0.0 alpha
创建好UIColor对象之后,就可以将其赋给文本视图的色彩属性了:
textView.textColor = myColorHue;
从UIColor中得到 RGB 各个值
UIColor *myWhiteTransparentColor = [ UIColor colorWithWhite: 1.0 alpha: 0.50 ];
UIColor *myColorHue = [ UIColor colorWithHue: 120.0 / 360.0
saturation: 0.75
brightness: 0.50
alpha: 1.0
];
UIColor *myColorRGB = [ UIColor colorWithRed: 0.75
green: 1.0
blue: 0.75
alpha: 1.0
];
如果你打算重用许多不同的UIColor对象,你也可以创建它们的实例:
UIColor *myWhiteTransparentColor = [ [ UIColor alloc ]
initWithWhite: 1.0 alpha: 0.50
];
UIColor *myColorHue = [ [ UIColor alloc ]
initWithHue: 120.0 / 360.0
saturation: 0.75
brightness: 0.50
alpha: 1.0
];
UIColor *myColorRGB = [ [ UIColor alloc ] initWithRed: 0.75
green: 1.0
blue: 0.75
alpha: 1.0
];
UIColor类还支持许多静态方法,可以创建系统颜色,这些颜色都经过iPhone的校正,以达到尽可能准确的地步。这些方法如下所示,均来自UIColor.h:
+ (UIColor *)blackColor; // 0.0 白色
+ (UIColor *)darkGrayColor; // 0.333 白色
+ (UIColor *)lightGrayColor; // 0.667 白色
+ (UIColor *)whiteColor; // 1.0 白色
+ (UIColor *)grayColor; // 0.5 白色
+ (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 白色, 0.0 alpha
创建好UIColor对象之后,就可以将其赋给文本视图的色彩属性了:
textView.textColor = myColorHue;
从UIColor中得到 RGB 各个值
CGFloat R, G, B; UIColor *uiColor = [lblDate textColor]; CGColorRef color = [uiColor CGColor]; int numComponents = CGColorGetNumberOfComponents(color); if (numComponents == 4) { const CGFloat *components = CGColorGetComponents(color); R = components[0]; G = components[1]; B = components[2]; }
相关文章推荐
- IOS疯狂基础之进入 App Store 打分
- IOS疯狂基础之UINavigationController
- IOS疯狂基础之屏幕旋转控制,获得当前方向
- IOS疯狂基础之GIF图片的显示
- IOS疯狂基础之AddressBook通讯录
- iOS 疯狂基础之NSDate 时间
- IOS疯狂基础之输入限制—手机号,金额
- IOS疯狂基础之-动画Animations
- IOS疯狂基础之键盘挡住输入框
- IOS 疯狂基础之 页面间跳转
- IOS疯狂基础之NSDictionary
- IOS疯狂基础之输入限制—手机号,金额
- IOS疯狂基础之NSNotificationCenter消息注册与撤销
- IOS疯狂基础之UIImage
- 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础(国内首部iOS 7相关著作,小伙伴们,学好iPhone/iPad应用开发,我们一起做土豪吧)
- IOS疯狂基础之观察者模式
- IOS疯狂基础之多线程编程NSThread
- IOS疯狂基础之隐藏系统键盘
- IOS疯狂基础之 通讯录