UI:关于RGB与16进制颜色值的转换
2015-09-12 12:01
435 查看
IOS基本图形绘制 参考
取色对照表 参照
加两个宏
#define UIColorFromHexWithAlpha(hexValue,a) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:a]
#define UIColorFromHex(hexValue) UIColorFromHexWithAlpha(hexValue,1.0)
然后 = UIColorFromHex(0x5cacee);
方法二:
为UIColor 添加一个延展方法
+ (UIColor*) colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue
{
return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0
green:((float)((hexValue & 0xFF00) >> 8))/255.0
blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue];
}
然后 [UIColor colorWithHex:0x5CACEE alpha:1];
-(id)initWithFrame:(CGRect)frame
-(instancetype)initWithFrame:(CGRect)frame
以他们开头的这两个初始化方法有什么区别?
比如你有一个类A,如果你重写一个init开头的方法,那么这个方法返回值也是A类的,但如果你写个其他名称的方法,就返回id了,instancetype可以保证依然返回一个A类的对象。省得你再强制类型转换。而且统一用instancetype显得整齐吧.
(2)
对于数组,字典,可变的不可以进行遍历,不可变的可以进行遍历,如要遍历,要把可变的数组、字典转化为不可变的然后再进行遍历。
(3)根据颜色视图得到三色值
如果想查看某一颜色的RGB值可以使用如下方法得到:
首先打开Launchpad
然后选择下面截图的左下角工具(数码测色计)将鼠标放到你选定的颜色视图上,数码测色计中就会显示出三色值
取色对照表 参照
页面背景改为 #5CACEE 的颜色。有两个方法
方法一:加两个宏
#define UIColorFromHexWithAlpha(hexValue,a) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:a]
#define UIColorFromHex(hexValue) UIColorFromHexWithAlpha(hexValue,1.0)
然后 = UIColorFromHex(0x5cacee);
方法二:
为UIColor 添加一个延展方法
+ (UIColor*) colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue
{
return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0
green:((float)((hexValue & 0xFF00) >> 8))/255.0
blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue];
}
然后 [UIColor colorWithHex:0x5CACEE alpha:1];
其他知识点:
(1)参考-(id)initWithFrame:(CGRect)frame
-(instancetype)initWithFrame:(CGRect)frame
以他们开头的这两个初始化方法有什么区别?
比如你有一个类A,如果你重写一个init开头的方法,那么这个方法返回值也是A类的,但如果你写个其他名称的方法,就返回id了,instancetype可以保证依然返回一个A类的对象。省得你再强制类型转换。而且统一用instancetype显得整齐吧.
(2)
对于数组,字典,可变的不可以进行遍历,不可变的可以进行遍历,如要遍历,要把可变的数组、字典转化为不可变的然后再进行遍历。
(3)根据颜色视图得到三色值
如果想查看某一颜色的RGB值可以使用如下方法得到:
首先打开Launchpad
然后选择下面截图的左下角工具(数码测色计)将鼠标放到你选定的颜色视图上,数码测色计中就会显示出三色值
相关文章推荐
- 【转】SoapUI5.0创建WebService接口模拟服务端
- UITableView中自定义Cell,自适应高度
- 给NGUI上的预设体动态添加点击事件
- leetcode: Distinct Subsequences
- EQueue文件持久化消息关键点设计思路
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lable1.'
- UIpickerView
- @PathVariable和@RequestParam的区别
- JPA字段映射(uuid,日期,枚举,@Lob)
- Leetcode_232_Implement Queue using Stacks
- Lettcode_232_Implement Queue using Stacks
- 用block改写UIButton点击事件和UIAlerView的按钮点击代理方法
- [iOS UI进阶 - 5.0] 手势解锁Demo
- 【Java】_图形用户界面(GUI)
- 注意uiview的两个重绘函数
- UI中一系列 个人错误总结
- [Leetcode]Closest Binary Search Tree Value
- [Leetcode]Closest Binary Search Tree Value II
- UISearchBar 的相关属性和delegate
- UIScrollView/UIPageControl/