IOS開發 一些常用的宏定義

根據個人使用習慣 ?自行修改Macro_前綴


//基礎引用

#define GJH(key)? ? ? ? ? ? ? ? NSLocalizedString(key, comment)

#define WS(weakSelf)? ? ? ? ? ? __weak __typeof(&*self)weakSelf = self;

#define App_Keywindow [UIApplication sharedApplication].delegate.window

#define App_Delegate (AppDelegate *)[UIApplication sharedApplication].delegate

#define NIB(name,bundleName)? ? ([UINib nibWithNibName:name bundle:bundleName])

//設備相關

#define Macro_ScreenBounds? ? ? ? ? [UIScreen mainScreen].bounds

#define Macro_ScreenWidth? ? ? ? ? ? [UIScreen mainScreen].bounds.size.width

#define Macro_ScreenHeight? ? ? ? ? [UIScreen mainScreen].bounds.size.height

#define Macro_Is_iphone? ? ? ? ? ? ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define Macro_Is_ipad? ? ? ? ? ? ? ? ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

#define Macro_Is_iPhoneX? ? ? ? ? ? (Macro_ScreenWidth >=375.0f&& Macro_ScreenHeight >=812.0f&& Macro_Is_iphone)

#define Macro_ScreenScale? ? ? ? ? ? (Macro_Is_ipad? ?1.3? :(Macro_ScreenWidth /375) )

//尺寸? iphonex 之后有safe 安全區域 概念

// Tabbar safe Top margin.

#define Macro_TabbarSafeTopMargin? ? ? ? (LL_iPhoneX ?44.f:0.f)

// Tabbar safe bottom margin.

#define Macro_TabbarSafeBottomMargin? ? ? ? (LL_iPhoneX ?34.f : 0.f)//[[[UIApplication sharedApplication] delegate] window].safeAreaInsets.bottom

// Navigation bar height.

#define? Macro_NavigationBarHeight? 44.f

// Tabbar height.

#define Macro_TabbarHeight? ? ? ? (LL_iPhoneX ? (49.f+34.f) :49.f)

// Status bar height.

#define Macro_StatusBarHeight? ? ? (Macro_Is_iPhoneX ?44.f : 20.f)//[[UIApplication sharedApplication] statusBarFrame].size.height

// Status bar & navigation bar height.

#define Macro_StatusBarAndNavigationBarHeight? (LL_iPhoneX ?88.f:64.f)

//顏色

#define Macro_ColorRGBA(r, g, b, a) [UIColor colorWithRed:(r /255.0) green:(g /255.0) blue:(b /255.0) alpha:a]

#define Macro_ColorRGB(r, g, b)? ? Macro_ColorRGBA(r, g, b,1.0)

#define Macro_Color16RGBA(rgbValue, alphaValue) [UIColor \

colorWithRed:((float)((rgbValue &0xFF0000) >>16))/255.0\

green:((float)((rgbValue &0x00FF00) >>8))/255.0\

blue:((float)(rgbValue &0x0000FF))/255.0\

alpha:alphaValue]

#define Macro_Color16RGB(rgbValue) Macro_Color16RGBA(rgbValue,1.0)

#define Macro_ColorRand? [UIColor colorWithRed:arc4random()%255/255.0fgreen:arc4random()%255/255.0fblue:arc4random()%255/255.0falpha:1.0f]

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。