OC个人开发常用宏

//常用宏

#ifndef IceMacros_h
#define IceMacros_h

/// 字符串转义
#define GetUTF8StringWithStr(string) [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:string] invertedSet]]
//NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:carPlate] invertedSet];
//NSString *utf8String =  [carPlate stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];

/**打印更多的信息 */
#define NSLog(format, ...) do { \
fprintf(stderr, "<%s : %d> %s\n----------\n", \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "----------\n\n\n"); \
} while (0)


/**循环引用 */
#define iceWeakSelf                 __weak typeof(self) weakSelf = self;
#define iceStrongSelf               __strong typeof(self) strongSelf = weakSelf;

/**以6s为标准做适配,返回的scale为相应比例 */
#define iceScaled(value)            (([UIScreen mainScreen].bounds.size.width)*(value)/375.0)

/**屏幕尺寸相关 */
#define iceScreenBounds             ([[UIScreen mainScreen] bounds])
#define iceScreenWidth              (iceScreenBounds.size.width)
#define iceScreenHeight             (iceScreenBounds.size.height)
#define iceScreenMaxLength          (MAX(iceScreenWidth, iceScreenHeight))
#define iceScreenMinLength          (MIN(iceScreenWidth, iceScreenHeight))


/**手机类型相关 */
#define ice_is_iPhone               (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/**判断是否为 iPhone X 系列 */
#define ice_is_iPhoneX \
({BOOL ice_is_iPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
ice_is_iPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(ice_is_iPhoneX);})


/**常见的高度 */
#define iceHeightStatusBar          (ice_is_iPhoneX?44:20.0f)
#define iceHeightSaveArea           (ice_is_iPhoneX?34.0f:0.0f)
#define iceHeightNavigationBar      (ice_is_iPhoneX?88.0f:64.0f)
#define iceHeightTabBar             (ice_is_iPhoneX?83.0f:49.0f)


/**系统版本 */
#define iceSystemVersion            ([[[UIDevice currentDevice] systemVersion] floatValue])

/**颜色 */
#define iceColor(r, g, b)           [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define iceColorAlpha(r, g, b, a)   [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
#define iceColorRandom              iceColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
#define iceColorHex(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]

#endif /* IceMacros_h */


//分环境打印
#ifdef DEBUG
#define iceLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define iceLog(...)do{}while(0)
#endif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • IT阅读 298评论 0 2
  • 仔细观察苹果的接口,会发现它用了很多的宏;或者当看某些大神的代码时,也会发现有很多的宏。这些宏简化了代码,使代码更...
    探索者的旅途阅读 517评论 0 0
  • 屏幕相关 数学相关
    Jackson_Chan阅读 250评论 0 0
  • 测试输出 Log 屏幕相关 系统相关 定义弱引用、强引用 定义警告宏 颜色宏 其他宏
    WeeverLu阅读 4,826评论 0 6
  • 一个字:烦。两个字:很烦。三个字:超级烦。四个字:烦恼人生。 今天是2016年的第一天,从羊年迈向...
    恬冼阅读 132评论 0 1