美文网首页
iOS高效 宏和常量

iOS高效 宏和常量

作者: David_Cap | 来源:发表于2016-01-21 14:18 被阅读249次

记录一些高效的宏

尺寸

int const StatusBar_HEIGHT = 20;
int const NavigationBar_HEIGHT = 44;
int const NavigationBarIcon = 20;
int const TabBar_HEIGHT = 49;
int const TabBarIcon = 30;

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) 

打印宏 NSLog

//直接替换NSLog
#if DEBUG  
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);  
#else  
#define NSLog(FORMAT, ...) nil  
#endif

系统宏

//获取版本
#define IOS_VERSION [[UIDevice currentDevice] systemVersion]

颜色宏

// 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]

// 获取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 BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

//清除背景色
#define CLEARCOLOR [UIColor clearColor]

其他宏

//方正黑体简体字体定义
#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//定义一个API
#define BaseURL                @"http://xxxxx/"
//登陆API
#define LoginURL              [APIURL stringByAppendingString:@"Login"]

参考致谢

link

相关文章

网友评论

      本文标题:iOS高效 宏和常量

      本文链接:https://www.haomeiwen.com/subject/fyvlkttx.html