iOS 常用宏

来源:互联网 发布:编程入门教学视频 编辑:程序博客网 时间:2024/06/07 06:51

// --------------屏幕宽高--------------------

#define ScreenWidth ([UIScreen mainScreen].bounds.size.width)

#define Screenheight ([UIScreen mainScreen].bounds.size.height)

//----------------------图片类---------------------------

//读取本地图片

#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定义UIImage对象

#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

//----------------------颜色类---------------------------

// aqua 浅蓝

#define qianLanColor [UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:1.000]

// sky 天蓝

#define tianLanColor [UIColor colorWithRed:0.400 green:0.800 blue:1.000 alpha:1.000]

// 浅红

#define qianHongColor [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000]

// 蓝紫色

#define lanZiColor [UIColor colorWithRed:0.400 green:0.400 blue:1.000 alpha:1.000]

#define hui1Color [UIColor colorWithWhite:0.902 alpha:1.000]// 1

#define hui2Color [UIColor colorWithWhite:0.800 alpha:1.000]// 2

#define hui3Color [UIColor colorWithWhite:0.702 alpha:1.000]// 3

#define hui4Color [UIColor colorWithWhite:0.600 alpha:1.000]// 4

#define hui5Color [UIColor colorWithWhite:0.502 alpha:1.000]// 5

#define hui6Color [UIColor colorWithWhite:0.498 alpha:1.000]// 6

#define hui7Color [UIColor colorWithWhite:0.400 alpha:1.000]// 7

#define hui8Color [UIColor colorWithWhite:0.298 alpha:1.000]// 8

#define hui9Color [UIColor colorWithWhite:0.200 alpha:1.000]// 9

#define hui10Color [UIColor colorWithWhite:0.098 alpha:1.000]// 10

// rgb颜色转换(16进制->10进制)

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue &0xFF0000) >>16))/255.0 green:((float)((rgbValue &0xFF00) >>8))/255.0 blue:((float)(rgbValue &0xFF))/255.0 alpha:1.0]

//带有RGBA的颜色设置

#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

// 获取RGB颜色

#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]

#define RGB(r,g,b) RGBA(r,g,b,1.0f)

// 随机色

#define WZYRandomColor [UIColor colorWithRed:arc4random_uniform(256) /255.0 green:arc4random_uniform(256) /255.0 blue:arc4random_uniform(256) /255.0 alpha:1]

//随机色透明度

#define WZYRandomColorWithAlpha(a) [UIColor colorWithRed:arc4random_uniform(256) /255.0 green:arc4random_uniform(256) /255.0 blue:arc4random_uniform(256) /255.0 alpha:(a)]

//清除背景色

#define CLEARCOLOR [UIColor clearColor]

//获取系统版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//获取当前语言

#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//单例化一个类

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \

\

static classname *shared##classname = nil; \

\

+ (classname *)shared##classname \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [[self alloc] init]; \

} \

} \

\

return shared##classname; \

} \

\

+ (id)allocWithZone:(NSZone *)zone \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [super allocWithZone:zone]; \

return shared##classname; \

} \

} \

\

return nil; \

} \

\

- (id)copyWithZone:(NSZone *)zone \

{ \

return self; \

}



0 0
原创粉丝点击