在ios開發的過程中合理的使用巨集定義能夠極大提高編碼的速度,下面是一些常用的巨集定義,部分內容來自網際網路
// 除錯狀態, 開啟log功能
#ifdef debug
#define gllog(...) nslog(__va_args__)
#define gllogmethod nslog(@"%s", __func__)
#else
// 發布狀態, 關閉log功能
#define gllog(...)
#define gllogmethod
#endif
#define rgb(r,g,b) [uicolor colorwithred:r/255. green:g/255. blue:b/255. alpha:1.]
#define rgba(r,g,b,a) [uicolor colorwithred:r/255. green:g/255. blue:b/255. alpha:a/100.]
//16進製制的顏色
#define rgbhex(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]
//主顏色
#define maincolor rgb(107,185,103)
//主背景色
#define mainbgcolor rgb(238,240,243)
#define uiheight [[uiscreen mainscreen] bounds].size.height
#define uiwidth [[uiscreen mainscreen] bounds].size.width
#define kfont(x) [uifont systemfontofsize:x]
#define kboldfont(x) [uifont boldsystemfontofsize:x]
#define mainfont14 [uifont systemfontofsize:14]
#define mainfont15 [uifont systemfontofsize:15]
#define mainfont12 [uifont systemfontofsize:12]
#define match(x) (x * uiwidth / 320)
//通知中心
#define glnotifycenter [nsnotificationcenter defaultcenter]
//main bundle載入xib檔案
#define mainbundle(xx) [[[nsbundle mainbundle] loadnibnamed:xx owner:self options:nil] lastobject]
//個人設定中心
#define glusercenter [nsuserdefaults standarduserdefaults]
//weakself
#define ws(weakself) __weak __typeof(&*self)weakself = self;
iOS常用巨集定義
獲取當前螢幕的寬高 define kscreenw uiscreen mainscreen bounds size.width define kscreenh uiscreen mainscreen bounds size.height 判斷當前系統版本 define ios9 uidevice c...
iOS 常用巨集定義
字串是否為空 define kstringisempty str str iskindofclass nsnull class str nil str length 1?yes no 陣列是否為空 define karrayisempty array array nil array iskindof...
iOS開發中常用到的巨集定義
字串是否為空 define kstringisempty str str iskindofclass nsnull class str nil str length 1 yes no 陣列是否為空 define karrayisempty array array nil array iskindof...