常用宏

//屏幕寬度:#define kSCREENWIDTH ? [[UIScreen mainScreen] bounds].size.width

//屏幕高度:#define kSCREENHEIGHT ? [[UIScreen mainScreen] bounds].size.height

//屏幕尺寸:#define WINSIZE [[UIScreen mainScreen] bounds].size

程序更新:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"程序地址"]]

//圖片名獲取圖片:#define IMG(name) [UIImage imageNamed:name]

//獲取系統(tǒng)版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)

#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)

#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)

#define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7)

#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8)

#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9)

#define isIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]==10)

#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4)

#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5)

#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6)

#define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7)

#define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8)

本地地址:#define UserInfoFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"本地文件名"]

//-------------------打印日志-------------------------

//DEBUG ?模式下打印日志,當(dāng)前行

#ifdef DEBUG

# ? define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

# ? define DLog(...)

#endif

//重寫NSLog,Debug模式下打印日志和當(dāng)前行數(shù)

#if DEBUG

#define NSLog(FORMAT, ...) fprintf(stderr,"\\nfunction:%s line:%d content:%s\\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(FORMAT, ...) nil

#endif

//獲取系統(tǒng)版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

//判斷是真機(jī)還是模擬器

#if TARGET_OS_IPHONE

//iPhone Device

#endif

#if TARGET_IPHONE_SIMULATOR

//iPhone Simulator

#endif

//讀取本地圖片

#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

//定義UIImage對(duì)象

#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

//----------------------顏色類---------------------------

// rgb顏色轉(zhuǎn)換(16進(jìn)制->10進(jìn)制)

#define UIColorFromRGB(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]

//帶有RGBA的顏色設(shè)置

#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

// 獲取RGB顏色

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

#define RGB(r,g,b) RGBA(r,g,b,1.0f)

//背景色

#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

//清除背景色

#define CLEARCOLOR [UIColor clearColor]

//定義一個(gè)API

#define APIURL ? ? ? ? ? ? ? ?@"http://xxxxx/"

//登陸API

#define APILogin ? ? ? ? ? ? ?[APIURL stringByAppendingString:@"Login"]

//G-C-D

#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 實(shí)例化

#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//單例化一個(gè)類

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \\

\\

static classname *shared##classname = nil; \\

\\

+ (classname *)shared##classname \\

{ \\

@synchronized(self) \\

{ \\

if (shared##classname == nil) \\

{ \\

shared##classname = [[self alloc] init]; \\

} \\

} \\

\\

return shared##classname; \\

} \\

\\

+ (id)allocWithZone:(NSZone *)zone \\

{ \\

@synchronized(self) \\

{ \\

if (shared##classname == nil) \\

{ \\

shared##classname = [super allocWithZone:zone]; \\

return shared##classname; \\

} \\

} \\

\\

return nil; \\

} \\

\\

- (id)copyWithZone:(NSZone *)zone \\

{ \\

return self; \\

}

#endif

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • iOS開發(fā)過程中,使用的一些常用宏定義 字符串是否為空#define kStringIsEmpty(str) ([...
    goyohol閱讀 5,535評(píng)論 30 84
  • ifndef MacroDefinition_h define MacroDefinition_h //-----...
    灰客閱讀 398評(píng)論 0 0
  • //AppDelegate #define APPDELEGATE [(AppDelegate*)[UIAppli...
    雙花紅棍小書童閱讀 358評(píng)論 1 0
  • 思之,念之 卻不可及 文字,是唯一 能夠觸摸到你的方式 春雨 細(xì)碎而又柔軟 滲透著一絲清涼 柔軟的柳條 吐出一簇簇...
    游游茶舍閱讀 361評(píng)論 0 1
  • 至今高考后兩個(gè)多月過去了在這個(gè)兩個(gè)多月時(shí)間里同學(xué)們都紛紛周游全國在空間朋友圈曬著精美無比的照片又有同學(xué)找到兼職可以...
    清悅橙閱讀 706評(píng)論 3 1

友情鏈接更多精彩內(nèi)容