//常用宏
#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个人开发常用宏
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...