本文已参与「新人创作礼」活动,一起开启掘金创作之路。
宏定义
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_PAD (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)
#define kScreenWidth (IS_IPHONE ? 375 : 768)
#define kScreenHeight (IS_IPHONE ? 667 : 1024)
#define kScreenWidthRatio (UIScreen.mainScreen.bounds.size.width / kScreenWidth)
#define kScreenHeightRatio (UIScreen.mainScreen.bounds.size.height / kScreenHeight)
#define AdaptedWidth(x) ceilf((x) * kScreenWidthRatio)
#define AdaptedHeight(x) ceilf((x) * kScreenHeightRatio)
#define AdaptedFontSize(R) [UIFont systemFontOfSize:AdaptedWidth(R)]
#define AdaptedBoldFontSize(R) [UIFont boldSystemFontOfSize:AdaptedWidth(R)]
// 是否是iPhoneX以上的机型
#define IS_IPHONEX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})
#define NAVIGATIONBAR_HEIGHT (IS_IPHONEX ? 88.0 : 64.0) //顶部导航栏h高度
#define TABBAR_HEIGHT (IS_IPHONEX ? 83.0 : 49.0) //底部tabbar高度
#define XBOTTOM_HEIGHT (IS_IPHONEX ? 34.0 : 0.0) //IphoneX底部高度
#define STATUS_BAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
#define WS(weakSelf) __weak __typeof(&*self) weakSelf = self; //弱引用
#define kImageNamed(name) [UIImage imageNamed:name]
禁止横屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}