iOS 開(kāi)發(fā)中常用的宏定義

iOS 開(kāi)發(fā)中常用的一些宏定義

1.關(guān)于設(shè)置顏色

//設(shè)置顏色
①.常見(jiàn)的方式
#define HHGlobalBackgroundColor [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]

#define HHCommonColor [UIColor colorWithRed:152/255.0 green:158/255.0 blue:0/255.0 alpha:1.0]  
②.書寫方便的宏
#define HHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

③.16進(jìn)制RGB的顏色轉(zhuǎn)換 --->推薦使用
#define HHColorFromHex(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í)直接調(diào)用宏定義:后面直接傳入 `0x(0~f)`
例如:[dateLabel setTextColor:ZNColorFromHex(0x989e00)];

④.隨機(jī)色
#define HHRandomColor JYJColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

2.自定義 Log

#ifdef DEBUG
#define HHLog(...) NSLog(__VA_ARGS__)
#else
#define HHLog(...)
#endif
#define HHLogFunc HHLog(@"%s",__func__);  

//重寫HHNSLog,Debug模式下打印日志和當(dāng)前行數(shù)
#if DEBUG
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#endif

3.弱引用

#define HHWeakSelf __weak typeof(self) weakSelf = self

4.通知

#define HHNotiCenter [NSNotificationCenter defaultCenter]

5.UserDefault

#define HHUserDefaults [NSUserDefaults standardUserDefaults]

6.常用的寬高

#define HHScreenH [UIScreen mainScreen].bounds.size.height
#define HHScreenW [UIScreen mainScreen].bounds.size.width
#define HHScreenBounds [UIScreen mainScreen].bounds
#define HHKeyWindow [UIApplication sharedApplication].keyWindow
#define HHRootTabBarController (UITabBarController *)HHKeyWindow.rootViewController

7.OC 的框架

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#pragma mark - 頭文件
#import "xxxxxx"   //放入要用的頭文件
#endif

8.沙盒路徑

#define HHCaches [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]

9.

內(nèi)容持續(xù)更新中,有用就拿走........順便點(diǎn)個(gè)贊,謝謝大家的支持!

最后編輯于
?著作權(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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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