iOS常用宏定义汇总

1.获取屏幕宽度与高度

#define SLScreenHeight [UIScreen mainScreen].bounds.size.width

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

2.根据rgb获得颜色

#define SLColor(r,g,b) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:1.0]

#define SLColorFromRGB(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]

3.版本判断

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

3.字号设置

#define SLFont(F) [UIFont systemFontOfSize:(F)]

4.由角度转换弧度 由弧度转换角度

#define SLDegreesToRadian(x)  (M_PI * (x) /180.0)

#define SLRadianToDegrees(radian)  (radian*180.0)/(M_PI)

5.获取当前语言

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

6.沙盒目录文件

//获取temp

#define SLPathTemp NSTemporaryDirectory()

//获取沙盒 Document

#define SLPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒 Cache

#define SLPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

7.判断字符串是否为空

#define SLStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length]< 1 ? YES : NO )

8.判断数组是否为空

#define SLArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)

9.判断字典是否为空

#define SLDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)

10.常用缩写

#define SLApplication  [UIApplication sharedApplication]

#define SLkKeyWindow  [UIApplication sharedApplication].keyWindow

#define SLAppDelegate  [UIApplication sharedApplication].delegate

#define SLUserDefaults  [NSUserDefaults standardUserDefaults]

#define SLNotificationCenter [NSNotificationCenter defaultCenter]

11.APP版本号

#define SLAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

12.获取当前语言

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

13.判断是否为iPhone

#define SLISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

14.判断是否为iPad

#define SLISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

15.随机生成颜色

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



作者:SL_iOS
链接:https://www.jianshu.com/p/d7c82b0dcf78
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

自己添加

/*! 字符串拼接 */

#define OCSTR(...)                      [NSString stringWithFormat:__VA_ARGS__]

#import "MYBaseHttpRequest.h"

#import "UIView+Extension.h"

/** frame */

#define Frame(x, y, width, height) CGRectMake((x),(y),(width),(height))

 

#define ColorWithRGB(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

 

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

 

#define UIColorFromString(rgbValue) [UIColor colorWithRed:((int)strtoul([[rgbValue substringWithRange:NSMakeRange(2, 2)] UTF8String], 0, 16))/255.0 green:((int)strtoul([[rgbValue substringWithRange:NSMakeRange(4, 2)] UTF8String], 0, 16))/255.0 blue:((int)strtoul([[rgbValue substringWithRange:NSMakeRange(6, 2)] UTF8String], 0, 16))/255.0 alpha:1.0]

 

 

 

 

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

#define BartintColor ColorWithRGB(39, 36, 50)

#define ViewColor ColorWithRGB(26, 29, 46)

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

#import "WTRemarkIsPlay.h"

/** Size*/

#define Size(width, height) CGSizeMake((width), (height))

#define Screen_Width [UIScreen mainScreen].bounds.size.width

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

#define Screen_bounds [UIScreen mainScreen].bounds

#define SCREEN_RATIO                    Screen_Width/375  /**<屏幕的宽比  基准375*/

#define SCREEN_RATIO_HEIGHT             Screen_Height/667  /**<屏幕的高比  基准667*/

#define FitWidth(w) (SCREEN_RATIO*(w))  // 根据4.7寸屏适配的宽度

#define FitHeight(h) (SCREEN_RATIO_HEIGHT*(h)) // 根据4.7寸屏适配的高度

#define rmStatusBarH ([UIApplication sharedApplication].statusBarFrame.size.height)//(44/20)

//判断iPhoneX页面的状态栏不能隐藏

#define IS_iPhoneX ((rmStatusBarH == 44.0) ? YES : NO)

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

 

//判断数组是否为空

#define SLArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值