美文网首页
OC个人开发常用宏

OC个人开发常用宏

作者: _iceCoke | 来源:发表于2019-03-15 11:08 被阅读0次
//常用宏

#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

相关文章

网友评论

      本文标题:OC个人开发常用宏

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