//
// PrefixHeader.pch
// DriveJouyney
//
// Created by Chan on 2019/5/15.
// Copyright ? 2019 Chan. All rights reserved.
//
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
// MARK: - scrollViewInsets
#define kAdjustsScrollViewInsets_NO(scrollView,vc)\
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
[scrollView performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\
} else {\
vc.automaticallyAdjustsScrollViewInsets = NO;\
}\
_Pragma("clang diagnostic pop") \
} while (0)
// MARK: - NSLOG
#ifdef DEBUG
#define LRLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define LRLog(...)
#endif
// MARK: - common use
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
#define kURLWithString(str) [NSURL URLWithString:str]
#define kGetUserDefaults(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]
#define kUserDefaults(key, value) [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]
#define kSynchronize [[NSUserDefaults standardUserDefaults] synchronize]
#define kRemoveOUserDefaults(key) [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]
// iOS6-iOS9判斷
#define ISIOS6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define ISIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define ISIOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define ISIOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
#define kIntToStr(intValue) ([NSString stringWithFormat:@"%@", @(intValue)])
#define kFloatToStr(floatValue) ([NSString stringWithFormat:@"%.2f", floatValue])
#define kNumberToStr(NumberValue) ([NSString stringWithFormat:@"%@", NumberValue])
#define kUint64ToStr(uint64) [@(uint64) stringValue]
#define kStrToInt(str) [str integerValue]
#define kStrToDouble(str) [str doubleValue]
// MARK: - setBorder&Radius
#define kViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]
// MARK: - loadNibView
#define kLoadNibView(className) [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil].lastObject
#define kAppWindow [[[UIApplication sharedApplication] delegate] window]
#define AppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define AppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define kIOS11Later [[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0
#define kAdaptiveRate [UIScreen mainScreen].bounds.size.height / 736
#define kFontScale kScreenWidth/375
#define kFontSize(size) [UIFont systemFontOfSize:size*kFontScale]
#define kNavBarTintColor UIColorHex(F05B48)
#define kWhiteColor [UIColor whiteColor]
#define kImage(named) [UIImage imageNamed:named]
// MARK: - frame &adapter
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kRect(x,y,w,h) CGRectMake(x*kFontScale, y*kAdaptiveRate, w*kFontScale, h*kAdaptiveRate)
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define KNavBarHeight (kStatusBarHeight+44)
#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define kTabbarHeight kDevice_Is_iPhoneX ?83: 49
#define kBodyHeight (kScreenHeight -KNavBarHeight)
#define kMiddleHeight (kBodyHeight -kTabbarHeight )
#define kSearchBarHeight 45
#define kNavigationHeight 44
// MARK: - Color
#define UIColorRGB(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0]
// 設(shè)置顏色 示例:UIColorHex(0x26A7E8)
#define UIColorHex(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]
// 設(shè)置顏色與透明度 示例:UIColorHEX_Alpha(0x26A7E8, 0.5)
#define UIColorHex_Alpha(rgbValue, al) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:al]
#pragma mark - CommonColor
// 導(dǎo)航欄背景顏色
#define kColorNavBground UIColorHex(0xf3ee64)
// 深灰色
#define kColorDarkgray UIColorHex(0x666666)
// 淡灰色-如普通界面的背景顏色
#define kColorLightgray UIColorHex(0xeeeeee)
// 灰色—如內(nèi)容字體顏色
#define kColorgrayContent UIColorHex(0x969696)
// 搜索焦點顏色
#define kTintColorSearch UIColorRGB(2, 162, 253)
// 主題背景色
#define kBackgroundColor UIColorHex(0xf2f2f2)
// cell高亮顏色
#define kCellHightedColor UIColorHex(0xe6e6e9)
// 通用的紅色文字顏色
#define kColorFontRed UIColorHex(0xe12228)
// 透明色
#define kColorClear [UIColor clearColor]
// 白色-如導(dǎo)航欄字體顏色
#define kColorWhite UIColorHex(0xffffff)
#define kColorLightWhite UIColorHex(0xf9f9f9)
#define kColorBgWhite UIColorHex(0xfbfbfb)
// 黑色-如輸入框輸入字體顏色或標題顏色
#define kColorBlack UIColorHex(0x333333)
// 黑色-細黑
#define kColorLightBlack UIColorHex(0x999999)
// 黑色-純黑
#define kColorDeepBlack UIColorHex(0x000000)
// 灰色—如列表cell分割線顏色樣式
#define kColorSeparatorline UIColorHex(0xdddddd)
// 灰色-邊框線顏色
#define kColorBorderline UIColorHex(0xb8b8b8)
// 按鈕不可用背景色
#define kColorGrayButtonDisable UIColorHex(0xdcdcdc)
// 綠色-如導(dǎo)航欄背景顏色
#define kColorGreenNavBground UIColorHex(0x38ad7a)
// 綠色
#define kColorGreen UIColorHex(0x349c6f)
// 深綠色
#define kColorDarkGreen UIColorHex(0x188d5a)
// 橙色
#define kColorOrange UIColorHex(0xf39700)
// 深橙色
#define kColorDarkOrange UIColorHex(0xe48437)
// 淡紫色
#define kColorLightPurple UIColorHex(0x909af8)
// 紅色
#define kColorRed UIColorHex(0xfd492e)
#define kColorLightRed UIColorHex(0xe4393c)
// 藍色
#define kColorBlue UIColorHex(0x00a0e9)
#define kColorLightBlue UIColorHex(0x3985ff)
// MARK: - block Self
#pragma mark - weakify( x ) && strongify( x )
/// block self
#ifndef weakify
#if __has_feature(objc_arc)
#define weakify( x ) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
autoreleasepool{} __weak __typeof__(x) __weak_##x##__ = x; \
_Pragma("clang diagnostic pop")
#else
#define weakify( x ) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
autoreleasepool{} __block __typeof__(x) __block_##x##__ = x; \
_Pragma("clang diagnostic pop")
#endif
#endif
#ifndef strongify
#if __has_feature(objc_arc)
#define strongify( x ) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
try{} @finally{} __typeof__(x) x = __weak_##x##__; \
_Pragma("clang diagnostic pop")
#else
#define strongify( x ) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
try{} @finally{} __typeof__(x) x = __block_##x##__; \
_Pragma("clang diagnostic pop")
#endif
// MARK: - fontSize
// *號字體
#define kFontSize(size) [UIFont systemFontOfSize:size]
/// *號粗體
#define kFontSizeBold(size) [UIFont boldSystemFontOfSize:size]
/// 9號字體
#define kFontSize9 [UIFont systemFontOfSize:9.0]
/// 10號字體
#define kFontSize10 [UIFont systemFontOfSize:10.0]
/// 11號字體
#define kFontSize11 [UIFont systemFontOfSize:11.0]
/// 12號字體
#define kFontSize12 [UIFont systemFontOfSize:12.0]
/// 13號字體
#define kFontSize13 [UIFont systemFontOfSize:13.0]
/// 14號字體
#define kFontSize14 [UIFont systemFontOfSize:14.0]
/// 15號字體
#define kFontSize15 [UIFont systemFontOfSize:15.0]
/// 16號字體
#define kFontSize16 [UIFont systemFontOfSize:16.0]
/// 17號字體
#define kFontSize17 [UIFont systemFontOfSize:17.0]
/// 18號字體
#define kFontSize18 [UIFont systemFontOfSize:18.0]
/// 19號字體
#define kFontSize19 [UIFont systemFontOfSize:19.0]
/// 20號字體
#define kFontSize20 [UIFont systemFontOfSize:20.0]
/// 21號字體
#define kFontSize21 [UIFont systemFontOfSize:21.0]
/// 22號字體
#define kFontSize22 [UIFont systemFontOfSize:22.0]
/// 24號字體
#define kFontSize24 [UIFont systemFontOfSize:24.0]
/// 25號字體
#define kFontSize25 [UIFont systemFontOfSize:25.0]
/// 30號字體
#define kFontSize30 [UIFont systemFontOfSize:30.0]
/// 50號字體
#define kFontSize50 [UIFont systemFontOfSize:50.0]
/// 60號字體
#define kFontSize60 [UIFont systemFontOfSize:60.0]
#pragma mark 大小-粗體
/// 10號粗字體
#define kFontSizeBold10 [UIFont boldSystemFontOfSize:10.0]
/// 11號粗字體
#define kFontSizeBold11 [UIFont boldSystemFontOfSize:11.0]
/// 12號粗字體
#define kFontSizeBold12 [UIFont boldSystemFontOfSize:12.0]
/// 13號粗字體
#define kFontSizeBold13 [UIFont boldSystemFontOfSize:13.0]
/// 14號粗字體
#define kFontSizeBold14 [UIFont boldSystemFontOfSize:14.0]
/// 15號粗字體
#define kFontSizeBold15 [UIFont boldSystemFontOfSize:15.0]
/// 16號粗字體
#define kFontSizeBold16 [UIFont boldSystemFontOfSize:16.0]
/// 17號粗字體
#define kFontSizeBold17 [UIFont boldSystemFontOfSize:17.0]
/// 18號粗字體
#define kFontSizeBold18 [UIFont boldSystemFontOfSize:18.0]
/// 19號粗字體
#define kFontSizeBold19 [UIFont boldSystemFontOfSize:19.0]
/// 20號字粗體
#define kFontSizeBold20 [UIFont boldSystemFontOfSize:20.0]
/// 21號字粗體
#define kFontSizeBold21 [UIFont boldSystemFontOfSize:21.0]
/// 22號字粗體
#define kFontSizeBold22 [UIFont boldSystemFontOfSize:22.0]
/// 23號字粗體
#define kFontSizeBold23 [UIFont boldSystemFontOfSize:23.0]
/// 24號字粗體
#define kFontSizeBold24 [UIFont boldSystemFontOfSize:24.0]
////////////////////////////////////////////////////////////////////////////////////
/*
各版本尺寸
1 iPhone4 640*960 320*480 2倍
2 iPhone4S 640*960 320*480 2倍
3 iPhone5 640*1136 320*568 2倍
4 iPhone5S 640*1136 320*568 2倍
5 iPhone5C 640*1136 320*568 2倍
6 iPhone6 750*1334 375*667 2倍
7 iPhone6 Plus 1242*2208 414*736 3倍
各版本比例
iPhone5荒吏, autoSizeScaleX=1帚屉,autoSizeScaleY=1移迫;
iPhone6, autoSizeScaleX=1.171875,autoSizeScaleY=1.17429577;
iPhone6Plus沼填,autoSizeScaleX=1.29375, autoSizeScaleY=1.295774括授;
*/
#define IS_IPAD_AutoSize (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE_AutoSize (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA_AutoSize ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH_AutoSize ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT_AutoSize ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH_AutoSize (MAX(SCREEN_WIDTH_AutoSize, SCREEN_HEIGHT_AutoSize))
#define SCREEN_MIN_LENGTH_AutoSize (MIN(SCREEN_WIDTH_AutoSize, SCREEN_HEIGHT_AutoSize))
#define IS_IPHONE_4_OR_LESS_AutoSize (IS_IPHONE_AutoSize && SCREEN_MAX_LENGTH_AutoSize < 568.0)
#define IS_IPHONE_5_AutoSize (IS_IPHONE_AutoSize && SCREEN_MAX_LENGTH_AutoSize == 568.0)
#define IS_IPHONE_6_AutoSize (IS_IPHONE_AutoSize && SCREEN_MAX_LENGTH_AutoSize == 667.0)
#define IS_IPHONE_6P_AutoSize (IS_IPHONE_AutoSize && SCREEN_MAX_LENGTH_AutoSize == 736.0)
////////////////////////////////////////////////////////////////////////////////////
#define AutoSizeDelegate_AutoSize ([[UIApplication sharedApplication] delegate])
#define AutoSizeScreenWidth_AutoSize ([[UIScreen mainScreen] bounds].size.width)
#define AutoSizeScreenHeight_AutoSize ([[UIScreen mainScreen] bounds].size.height)
#define AutoSizeScaleX_AutoSize ((AutoSizeScreenHeight_AutoSize > 480.0) ? (AutoSizeScreenWidth_AutoSize / 320.0) : 1.0)
#define AutoSizeScaleY_AutoSize ((AutoSizeScreenHeight_AutoSize > 480.0) ? (AutoSizeScreenHeight_AutoSize / 568.0) : 1.0)
////////////////////////////////////////////////////////////////////////////////////
CG_INLINE CGFloat
AutoCGRectGetMinX(CGRect rect)
{
CGFloat x = rect.origin.x * AutoSizeScaleX_AutoSize;
return x;
}
CG_INLINE CGFloat
AutoCGRectGetMinY(CGRect rect)
{
CGFloat y = rect.origin.y * AutoSizeScaleX_AutoSize;
return y;
}
CG_INLINE CGFloat
AutoCGRectGetWidth(CGRect rect)
{
CGFloat width = rect.size.width * AutoSizeScaleX_AutoSize;
return width;
}
CG_INLINE CGFloat
AutoCGRectGetHeight(CGRect rect)
{
CGFloat height = rect.size.height * AutoSizeScaleX_AutoSize;
return height;
}
CG_INLINE CGPoint
AutoCGPointMake(CGFloat x, CGFloat y)
{
CGPoint point;
point.x = x * AutoSizeScaleX_AutoSize;
point.y = y * AutoSizeScaleY_AutoSize;
return point;
}
CG_INLINE CGSize
AutoCGSizeMake(CGFloat width, CGFloat height)
{
CGSize size;
size.width = width * AutoSizeScaleX_AutoSize;
size.height = height * AutoSizeScaleY_AutoSize;
return size;
}
CG_INLINE CGRect
AutoCGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
CGRect rect;
rect.origin.x = x * AutoSizeScaleX_AutoSize;
rect.origin.y = y * AutoSizeScaleY_AutoSize;
rect.size.width = width * AutoSizeScaleX_AutoSize;
rect.size.height = height * AutoSizeScaleY_AutoSize;
return rect;
}
////////////////////////////////////////////////////////////////////////////////////
CG_INLINE CGRect
AutoWHCGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height, BOOL autoW, BOOL autoH)
{
CGRect rect;
rect.origin.x = x;
rect.origin.y = y;
rect.size.width = (autoW ? (width * AutoSizeScaleX_AutoSize) : width);
rect.size.height = (autoH ? (height * AutoSizeScaleY_AutoSize) : height);
return rect;
}
CG_INLINE CGFloat
AutoWHGetHeight(CGFloat height)
{
CGFloat autoHeight = height * AutoSizeScaleY_AutoSize;
return autoHeight;
}
CG_INLINE CGFloat
AutoWHGetWidth(CGFloat width)
{
CGFloat autoWidth = width * AutoSizeScaleX_AutoSize;
return autoWidth;
}
#endif
#endif /* PrefixHeader_pch */
iOS常用的宏定義(實用tips)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門晚伙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來吮龄,“玉大人,你說我怎么就攤上這事咆疗±熘悖” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵午磁,是天一觀的道長尝抖。 經(jīng)常有香客問我,道長迅皇,這世上最難降的妖魔是什么昧辽? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮喧半,結(jié)果婚禮上奴迅,老公的妹妹穿的比我還像新娘青责。我一直安慰自己挺据,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布脖隶。 她就那樣靜靜地躺著扁耐,像睡著了一般。 火紅的嫁衣襯著肌膚如雪产阱。 梳的紋絲不亂的頭發(fā)上婉称,一...
- 文/蒼蘭香墨 我猛地睜開眼藻烤,長吁一口氣:“原來是場噩夢啊……” “哼绷雏!你這毒婦竟也來了头滔?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布逝段,位于F島的核電站,受9級特大地震影響割捅,放射性物質(zhì)發(fā)生泄漏奶躯。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一亿驾、第九天 我趴在偏房一處隱蔽的房頂上張望嘹黔。 院中可真熱鬧,春花似錦莫瞬、人聲如沸儡蔓。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽喂江。三九已至,卻和暖如春旁振,著一層夾襖步出監(jiān)牢的瞬間获询,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- //設(shè)備型號 define IS_IPAD [[UIDevice currentDevice] userI...
- iOS開發(fā)過程中使用一些常用的宏可以提高開發(fā)效率啡捶,提高代碼的重用性;將這些宏放到一個頭文件里然后再放到工程中的-P...
- 1.8密鑰驗證 筆記內(nèi)容:私鑰本地奸焙,公鑰服務(wù)器可以看到的是公鑰瞎暑,私鑰需要保存的,可以密鑰添加密碼与帆,和備注了赌。使用密鑰...
- 第五場打完我寫了一篇《雙王炸起水花阵翎,希望還未破滅》時說逢并,“這是可能是今年總決賽的轉(zhuǎn)折,搶七可能在路上!”這幾天我也...
- 1.丑話說在前頭,用制度約束愛沾便宜的人拱绑,善于發(fā)現(xiàn)制度漏洞,員工也要積極參與完善制度蹈集。 2.監(jiān)督制度管理,杜絕出現(xiàn)...