美文网首页
2021-12-21 常用宏

2021-12-21 常用宏

作者: 两米长的大白菜 | 来源:发表于2021-12-27 11:38 被阅读0次

一些常用宏

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_FullScreen \
({BOOL isFullScreen = NO;\
if (@available(iOS 11.0, *)) {\
isFullScreen = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isFullScreen);})

/**
 状态栏 高度
 iPhone XR/11                                           48
 iPhone X/11 Pro/ 11 Pro Max/12 mini      44
 iPhone 12/12 Pro/Pro Max                      47
 无刘海                                                      20
 */
#define kStatusBarHeight \
({CGFloat statusBarHeight = 0;\
if (@available(iOS 13.0, *)) {\
    statusBarHeight = [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager.statusBarFrame.size.height;\
} else {\
    statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;\
}\
(statusBarHeight);})

#define  kNavigationBarHeight (kStatusBarHeight + 44) // 导航栏默认44
#define Tab_Safe_Height  (IS_FullScreen?34.f:0.f)
#define kTabBarHeight       (Tab_Safe_Height+49.f)

#define  SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define  SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)



#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"[文件名:%s]\n [函数名:%s] \n [行号: %d] \n" fmt), __FILE__, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define DLogRect(rect)  DLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y,rect.size.width, rect.size.height)
#define DLogPoint(pt) DLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)
#define DLogSize(size) DLog(@"%s w=%f, h=%f", #size, size.width, size.height)
#define ALog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#define DLog(...)
#define DLogRect(rect)
#define DLogPoint(pt)
#define DLogSize(size)
#define ALog(...)
#endif

附:总结 状态栏、导航栏 和 tabbar 高度

相关文章

网友评论

      本文标题:2021-12-21 常用宏

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