iOS 通用巨集定義
阿新 • • 發佈:2019-01-26
最近要搭建新的專案 先把通用的巨集定義給整理一下
//
// APPUtil.h
// Macro
//
// Created by WY on 2018/6/15.
// Copyright © 2018年 WY. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface APPUtil : NSObject
/**
輸出時年月日分秒毫秒
*/
+ (NSString *_Nullable)lr_stringDate;
@end
//
// APPUtil.m
// Macro
//
// Created by WY on 2018/6/15.
// Copyright © 2018年 WY. All rights reserved.
//
#import "APPUtil.h"
@implementation APPUtil
///輸出時年月日分秒毫秒
+ (NSString *)lr_stringDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
return dateString;
}
@end
//
// APPMacro.h
// Macro
//
// Created by WY on 2018/6/15.
// Copyright © 2018年 WY. All rights reserved.
//
#import "APPUtil.h"
#ifndef APPMacro_h
#define APPMacro_h
#ifdef DEBUG
#define LRString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent
#define NSLog(...) printf("%s: %s 第%d行: %s\n\n",[[APPUtil lr_stringDate] UTF8String], [LRString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);
#else
#define NSLog(...){}
#endif
/**
獲取螢幕寬高
*/
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height
/**
根據ip6的螢幕來拉伸
*/
#define kRealWidthValue(width) ((width)*(KScreenWidth/375.0f))
#define kRealHeightValue(height) ((height)*(KScreenWidth/667.0f))
/**
強弱引用
*/
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
/**
顏色
*/
#undef kRGB
#define kRGB(R,G,B) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:1.0f]
#undef kRGBA
#define kRGBA(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
/*
16進位制轉色值
*/
#define kColorFromRGB(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]
/*
16進位制轉色值帶透明度
*/
#define kColorFromRGBA(rgbValue, alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 blue:((float)(rgbValue & 0x0000FF))/255.0 alpha:alphaValue]
/*
隨機色生成
*/
#define kRandomColorKRGBColor (arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)
/*
property屬性快速宣告
*/
#define kPropertyString(s) @property(nonatomic,copy)NSString *s
#define kPropertyNSInteger(s) @property(nonatomic,assign)NSInteger s
#define kPropertyFloat(s) @property(nonatomic,assign)float s
#define kPropertyLongLong(s) @property(nonatomic,assign)long long s
#define kPropertyNSDictionary(s) @property(nonatomic,strong)NSDictionary *s
#define kPropertyNSArray(s) @property(nonatomic,strong)NSArray *s
#define kPropertyNSMutableArray(s) @property(nonatomic,strong)NSMutableArray *s
/*
字型
*/
#define kFontBold(X) [UIFont boldSystemFontOfSize:X]
#define kFont(X) [UIFont systemFontOfSize:X]
/*
定義UIImage物件
*/
#define kImageName(X) [UIImage imageNamed:X]
/*
列印當前方法名
*/
#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s",__PRETTY_FUNCTION__)
/*
view邊框
*/
#define kViewBorderRadius(view,radius,width,color)\
[view.layer setCornerRadius:radius];\
[view.layer setMasksToBounds:YES];\
[view.layer setBorderWidth:width];\
[view.layer setBorderColor:[color CGColor]];
/*
view圓角
*/
#define kViewRadius(View,Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
/*
單例化一個類
*/
#define SINGLETON_FOR_HEADER(className)\
\
+(className *)shared##className;
#define SINGLETON_FOR_CLASS(className)\
\
+(className *)shared##className { \
static className *shared##className = nil;\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken,^{ \
shared##className =[[self alloc]init];\
});\
return shared##className;\
}
/*
警告提示
匯入第三方庫:CoreSVP
*/
#define APCoreSVPSuccess(msg) [CoreSVP showSVPWithType:CoreSVPTypeSuccess Msg:msg duration:1.5 allowEdit:NO beginBlock:nil completeBlock:nil];
#define APCoreSVPError(msg) [CoreSVP showSVPWithType:CoreSVPTypeError Msg:msg duration:1.5 allowEdit:NO beginBlock:nil completeBlock:nil];
#define APCoreSVPLoading(msg,allow) [CoreSVP showSVPWithType:CoreSVPTypeLoadingInterface Msg:msg duration:0 allowEdit:allow beginBlock:nil completeBlock:nil];
#define APCoreHiddenSVPLoading [CoreSVP dismiss];
#endif /* APPMacro_h */