
本文共 8627 字,大约阅读时间需要 28 分钟。
iOS������������������������������
������������
������������C������������������������������������������������������������������������������������������������������������������ iOS ������������������������������������������ UI ���������Log������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������UI ������
������������������ UI ������������������������������������������������������������������������������
// NavBar ��� StatusBar ���������#define NavBarHeight 44#define StatusBarHeight 20// ������������������#define ScreenWidth [UIScreen mainScreen].bounds.size.width#define ScreenHeight [UIScreen mainScreen].bounds.size.height// ������������������#define ContentHeight (ScreenHeight - NavBarHeight - StatusBarHeight)// ���������������#define KeyWindow [UIApplication sharedApplication].keyWindow// ���������������#define ScreenResolution (ScreenWidth * ScreenHeight * [UIScreen mainScreen].scale)
������Log������
���������������������������������������������������������������������������������������������������
// ������ `NSLog` ���������������������#define CustomLog(format, ...) do { fprintf(stderr, "[%s : %d] %s\n", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __func__); NSLog((format), ##__VA_ARGS__); fprintf(stderr, "\n");} while (0)
���������������������������
������������������������������������������������������������������������������������������������
// ������������������#define IOSVersion [[[UIDevice currentDevice] systemVersion] floatValue]#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]// ������������������#define CurrentLanguage ([NSLocale preferredLanguages] objectAtIndex:0)// ���������������#define IsPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)#define IsPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)#define IsiPhone [[UIDevice currentDevice] model] == "iPod touch"// ������������������#define iPhone5SE ([[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f)#define iPhone6Plus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f// ������������������#define IOSVersion6Later (([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) ? YES : NO)#define IOSVersion7later (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) ? YES : NO)#define IOSVersion8later (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? YES : NO)#define IOSVersion9later (([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) ? YES : NO)#define IOSVersion10later (([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) ? YES : NO)// ������������������������#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_ETA(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)// ������������#define IsPortrait ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
������������������
���������������������������������������������������������������������������������������
// RGBA ������������#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]// ������������������������������#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]// RGB16 ���������������������#define RGB16Color(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 NotificationCenter [NSNotificationCenter defaultCenter]// ������������#define Post_Notify(_notiName, _obj, _userInfo) [[NotificationCenter defaultCenter] postNotificationName:_notiName object:_obj userInfo:_userInfo]// ���������������#define Add_Observer(_notiName, _observer, _selector, _object) [[NotificationCenter defaultCenter] addObserver:_observer selector:@selector(_selector) name:_notiName object:_object]// ���������������#define Remove_Observer(_observer) [[NotificationCenter defaultCenter] removeObserver:_observer]
������������������
������������������������������������������������������������������
// UserDefaults ���������#define USER_DEFAULT [NSUserDefaults standardUserDefaults]// Temp ������#define kTempPath NSTemporaryDirectory()// Doc ��� Caches ������#define kDocPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
������������������
��������������������������������������������������� Singleton ������������������������
// ARC ���������������������#define SingleH(name) +(instancetype) share##name#if __has_feature(objc_arc)#define SingleM(name) static id _instance; +(instancetype) allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{_instance = [super allocWithZone:zone]; return _instance; }); return _instance; }+(instancetype) share##name { return [[self alloc] init]; }-(id) copyWithZone:(NSZone *)zone { return _instance; }-(id) mutableCopyWithZone:(NSZone *)zone { return _instance; }#������������ MRC ���������������������#else#define SingleM(name) static id _instance; +(instancetype) allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{_instance = [super allocWithZone:zone]; return _instance; }); return _instance; }+(instancetype) share##name { return [[self alloc] init]; }...#endif
���������������
���������������������������������������������������������������������
#define CurrentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]
������������������
���������������������������������������������������������������������������
// ������������#define CameraStatus [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]#define CameraDenied (CameraStatus == AVAuthorizationStatusRestricted || CameraStatus == AVAuthorizationStatusDenied)#define CameraAllowed !CameraDenied// ������������#define LocationStatus [CLLocationManager authorizationStatus]#define LocationAllowed ([CLLocationManager locationServicesEnabled] && ![LocationStatus == kCLAuthorizationStatusDenied || LocationStatus == kCLAuthorizationStatusRestricted])#define LocationDenied !LocationAllowed// ������������������#define PushClose (([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) ? ([[UIApplication sharedApplication] currentUserNotificationSettings].types == UIUserNotificationTypeNone) : ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone))#define PushOpen !PushClose
���������������������
���������������������������������������������������
#define LoadImage(file, type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:type]]#define LoadArray(file, type) [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:type]]#define LoadDict(file, type) [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:type]]
���������Block ������
���������������������������������������������������
// ���������#define WeakWithNameAndObject(obj, name) __weak typeof(obj) weak##name = obj// ���������#define StrongWithNameAndObject(obj, name) __strong typeof(obj) strong##name = obj
��������������������������������������� iOS ������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
