国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS開發 常用宏定義

2019-11-09 19:02:25
字體:
來源:轉載
供稿:網友

#ifndef Public_h

#define Public_h

// 1.判斷是否為iOS7

#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)

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

// 2.獲得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 RandomColor                 RGB(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

// 3.是否為4inch

#define fourInch ([UIScreen mainScreen].bounds.size.height == 568)

// 4.屏幕大小尺寸

#define screen_width [UIScreen mainScreen].bounds.size.width

#define screen_height [UIScreen mainScreen].bounds.size.height

//重新設定view的Y值

#define setFrameY(view, newY) view.frame = CGRectMake(view.frame.origin.x, newY, view.frame.size.width, view.frame.size.height)

#define setFrameX(view, newX) view.frame = CGRectMake(newX, view.frame.origin.y, view.frame.size.width, view.frame.size.height)

#define setFrameH(view, newH) view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, newH)

#define setFrameW(view, newW) view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, newW, view.frame.size.height)

//取view的坐標及長寬

#define W(view)    view.frame.size.width

#define H(view)    view.frame.size.height

#define X(view)    view.frame.origin.x

#define Y(view)    view.frame.origin.y

#define ViewBottomY(view) Y(view)+H(view)

#define ViewWidthX(view) X(view)+W(view)

//5.常用對象

#define APPDELEGATE ((AppDelegate *)[UIapplication sharedApplication].delegate)

#define APP_TOPWIMDOW [[UIApplication sharedApplication].windows lastObject]

//重寫NSLog,Debug模式下打印日志和當前行數

#if DEBUG

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

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

#else

#define NSLog(FORMAT, ...) nil

#endif

//----------------------其他----------------------------

// View 圓角和加邊框

#define ViewBorderRadius(View, Radius, Width, Color)/

/

[View.layer setCornerRadius:(Radius)];/

[View.layer setMasksToBounds:YES];/

[View.layer setBorderWidth:(Width)];/

[View.layer setBorderColor:[Color CGColor]]

// View 圓角

#define ViewRadius(View, Radius)/

/

[View.layer setCornerRadius:(Radius)];/

[View.layer setMasksToBounds:YES]

// 是否ipad#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)// 是否iPad#define someThing (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)? ipad: iphone //獲取系統版本#define IOS_VERSION [[UIDevice currentDevice] systemVersion] floatValue]#define CurrentSystemVersion [UIDevice currentDevice] systemVersion]
//方正黑體簡體字體定義#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

#endif /* Public_h */

以及單例模式

// .h文件的實現#define SingletonH(methodName) + (instancetype)shared##methodName;// .m文件的實現#if __has_feature(objc_arc) // 是ARC#define SingletonM(methodName) /static id _instace = nil; /+ (id)allocWithZone:(struct _NSZone *)zone /{ /if (_instace == nil) { /static dispatch_once_t onceToken; /dispatch_once(&onceToken, ^{ /_instace = [super allocWithZone:zone]; /}); /} /return _instace; /} //- (id)init /{ /static dispatch_once_t onceToken; /dispatch_once(&onceToken, ^{ /_instace = [super init]; /}); /return _instace; /} //+ (instancetype)shared##methodName /{ /return [[self alloc] init]; /} /+ (id)copyWithZone:(struct _NSZone *)zone /{ /return _instace; /} //+ (id)mutableCopyWithZone:(struct _NSZone *)zone /{ /return _instace; /}#else // 不是ARC#define SingletonM(methodName) /static id _instace = nil; /+ (id)allocWithZone:(struct _NSZone *)zone /{ /if (_instace == nil) { /static dispatch_once_t onceToken; /dispatch_once(&onceToken, ^{ /_instace = [super allocWithZone:zone]; /}); /} /return _instace; /} //- (id)init /{ /static dispatch_once_t onceToken; /dispatch_once(&onceToken, ^{ /_instace = [super init]; /}); /return _instace; /} //+ (instancetype)shared##methodName /{ /return [[self alloc] init]; /} //- (oneway void)release /{ //} //- (id)retain /{ /return self; /} //- (NSUInteger)retainCount /{ /return 1; /} /+ (id)copyWithZone:(struct _NSZone *)zone /{ /    return _instace; /} / /+ (id)mutableCopyWithZone:(struct _NSZone *)zone /{ /    return _instace; /}#endif  //Singleton.h其中這個單例模式先在UserInfoModel.h中

SingletonH(UserInfoModel);再在.m中

SingletonM(UserInfoModel);

初始化賦值

//UserInfoModel是個單例,此處初始化后,數據會一直隨應用程序的啟動而存在 UserInfoModel *userInfoModel = [UserInfoModel mj_objectWithKeyValues:responseData.responSEObject[0]];
//其中mj_objectWithKeyValues是mj方法的其中一種,詳情請看本人另一篇文章介紹常用mj調用獲取單例中的值,比如獲取id

[UserInfoModel sharedUserInfoModel].ID


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临邑县| 新宁县| 贵德县| 塔河县| 出国| 黑山县| 涟源市| 宾阳县| 锦屏县| 许昌县| 宣威市| 湖州市| 偃师市| 上虞市| 板桥市| 古丈县| 安宁市| 江都市| 桑植县| 台南县| 扬中市| 湘乡市| 蓝田县| 佛学| 徐闻县| 营山县| 绵竹市| 西和县| 竹北市| 新兴县| 双流县| 磴口县| 吉隆县| 海原县| 响水县| 鹤山市| 嘉荫县| 绿春县| 邵阳县| 绍兴县| 古浪县|