2021-12-21 常用宏

一些常用宏

#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 高度

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,497评论 2 59
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,956评论 1 180
  • iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...
    goyohol阅读 10,744评论 30 84
  • iOS开发常用的第三方库,学习资源等,持续更新中。。。 资料 王巍[https://onevcat.com/#bl...
    barry阅读 9,588评论 0 123
  • ![Flask](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAW...
    极客学院Wiki阅读 12,162评论 0 3