iOS pch中或者common.h中常见的代码

// 是否模拟器

#define isSimulator (NSNotFound != [[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location)


//按设备宽度做适配

#define SCALE_WIDTH(x) (([UIScreen mainScreen].bounds.size.width/320.0)*(x))

//按设备高度适配--修改

#define SCALE_HEIGHT(x) (([UIScreen mainScreen].bounds.size.height/480.0)*(x))


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

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

// View 坐标(x,y)和宽高(width,height)

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

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

#define WIDTH(v)                (v).frame.size.width

#define HEIGHT(v)               (v).frame.size.height


#define MinX(v)                 CGRectGetMinX((v).frame)

#define MinY(v)                 CGRectGetMinY((v).frame)


#define MidX(v)                 CGRectGetMidX((v).frame)

#define MidY(v)                 CGRectGetMidY((v).frame)


#define MaxX(v)                 CGRectGetMaxX((v).frame)

#define MaxY(v)                 CGRectGetMaxY((v).frame)


#define RECT_CHANGE_x(v,x)          CGRectMake(x, Y(v), WIDTH(v), HEIGHT(v))

#define RECT_CHANGE_y(v,y)          CGRectMake(X(v), y, WIDTH(v), HEIGHT(v))

#define RECT_CHANGE_point(v,x,y)    CGRectMake(x, y, WIDTH(v), HEIGHT(v))

#define RECT_CHANGE_width(v,w)      CGRectMake(X(v), Y(v), w, HEIGHT(v))

#define RECT_CHANGE_height(v,h)     CGRectMake(X(v), Y(v), WIDTH(v), h)

#define RECT_CHANGE_size(v,w,h)     CGRectMake(X(v), Y(v), w, h)


// 系统控件默认高度

#define kStatusBarHeight        (20.f)


#define kTopBarHeight           (44.f)

#define kBottomBarHeight        (49.f)


#define kCellDefaultHeight      (44.f)


#define kEnglishKeyboardHeight  (216.f)

#define kChineseKeyboardHeight  (252.f)


//TopBar 第一个按钮起始x位置

#define kTopBarItemStartSpacing (5)

//TopBar 按钮上间隙

#define kTopBarItemSpacing (15)


#pragma mark - Funtion Method (方法)


//** 沙盒路径

#define PATH_OF_APP_HOME    NSHomeDirectory()

#define PATH_OF_TEMP        NSTemporaryDirectory()

#define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]


// PNG JPG 图片路径

#define PNGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"png"]

#define JPGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"jpg"]

#define PATH(NAME, EXT)         [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]


// 加载图片

#define PNGIMAGE(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"png"]]

#define JPGIMAGE(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"jpg"]]

#define IMAGE(NAME, EXT)        [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]]


#pragma mark -  字体大小(常规/粗体)


#define BOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]

#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE]

#define FONT(NAME, FONTSIZE)    [UIFont fontWithName:(NAME) size:(FONTSIZE)]

#pragma mark -  颜色(RGB)

#define RGBCOLOR(r, g, b)       [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]

#define RGBACOLOR(r, g, b, a)   [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]


// RGB颜色转换(16进制->10进制)

#define UIColorFromRGB(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]


#pragma mark - 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]


#pragma mark -  当前版本

#define FSystemVersion          ([[[UIDevice currentDevice] systemVersion] floatValue])

#define DSystemVersion          ([[[UIDevice currentDevice] systemVersion] doubleValue])

#define SSystemVersion          ([[UIDevice currentDevice] systemVersion])


// 当前语言

#define CURRENTLANGUAGE         ([[NSLocale preferredLanguages] objectAtIndex:0])


// UIView - viewWithTag

#define VIEWWITHTAG(_OBJECT, _TAG)\

\

[_OBJECT viewWithTag : _TAG]


// 本地化字符串

/** NSLocalizedString宏做的其实就是在当前bundle中查找资源文件名“Localizable.strings”(参数:键+注释) */

#define LocalString(x, ...)     NSLocalizedString(x, nil)

/** NSLocalizedStringFromTable宏做的其实就是在当前bundle中查找资源文件名“xxx.strings”(参数:键+文件名+注释) */

#define AppLocalString(x, ...)  NSLocalizedStringFromTable(x, @"someName", nil)



#if TARGET_OS_IPHONE

/** iPhone Device */

#endif


#if TARGET_IPHONE_SIMULATOR

/** iPhone Simulator */

#endif


// ARC

#if __has_feature(objc_arc)

/** Compiling with ARC */

#else

/** Compiling without ARC */

#endif


#pragma mark - Constants (常量)



/** 时间间隔 */

#define kHUDDuration            (1.f)


/** 一天的秒数 */

#define SecondsOfDay            (24.f * 60.f * 60.f)

/** 秒数 */

#define Seconds(Days)           (24.f * 60.f * 60.f * (Days))


/** 一天的毫秒数 */

#define MillisecondsOfDay       (24.f * 60.f * 60.f * 1000.f)

/** 毫秒数 */

#define Milliseconds(Days)      (24.f * 60.f * 60.f * 1000.f * (Days))


#pragma mark - 密码相关


//必须32个字符

extern NSString *dbKey;

extern NSString *dataPW;


#pragma mark - 程序主要颜色


#define YKT_MAIN_COLOR YKT_Cb1


#define YKT_TEXT_TITLE_FONT_SIZE 20

#define YKT_TEXT_CONTEXT_FONT_SIZE 15


#pragma mark weak self


#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值