iOS 通用宏定义总结

为了方便开发,经常会用到一些宏定义梳理了之前项目中用到的,又查漏补缺挑选了一些网络上比较不错的,总结了一份分享给大家。


//1,***获取系统对象

#define kApplication        [UIApplication sharedApplication]

#define kUserDefaults       [NSUserDefaults standardUserDefaults]

#define kNotificationCenter [NSNotificationCenter defaultCenter]

//2,***获取屏幕宽高

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

#define kScreenHeight [[UIScreen mainScreen] bounds].size.height

#define kScreen_Bounds [UIScreen mainScreen].bounds


//3,***根据ip6的屏幕来拉伸

#define kRealWidth(with) ((with)*(KScreenWidth/375.0f))

#define kRealHeight(height) ((height)*(kScreenHeight/667.0f))


//4,***强弱引用(执行完A ## B后变为AB(连接A和B并去掉空格)

#define kWeakSelf(type)  __weak typeof(type) weak##type = type;

#define kStrongSelf(type) __strong typeof(type) type = weak##type;


//5,***View圆角和加边框

#define ViewBorderRadius(View, Radius, Width, Color)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES];\

[View.layer setBorderWidth:(Width)];\

[View.layer setBorderColor:[Color CGColor]]


//6,***View圆角

#define ViewRadius(View, Radius)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES]


//7,***颜色

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

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

//随机色生成

#define kRandomColor    UIColorWithRGBA(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256),1  


//8,***字体

#define BoldSystemFont(fontSize) [UIFont boldSystemFontOfSize:fontSize]

#define SystemFont(fontSize)   [UIFont systemFontOfSize:fontSize]

#define FONT(fontName, fontSize) [UIFont fontWithName:(fontName) size:(fontSize)]


//9,***当前系统版本(iOS版本)

#define CurrentSystemVersion [[UIDevice currentDevice].systemVersion doubleValue]


//10,***发送通知

#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];


//11,***DEBUG 模式下打印日志,当前行

#ifdef DEBUG

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#define DLog(...)

#endif





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值