常用的宏定义

2016-11-17  本文已影响0人  无所待

//获取屏幕 宽度、高度

//宽度

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

//高度

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

// 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]

// 可以更改透明度

#define UIColorFromRGBA(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

#ifdef DEBUG

#define ZKLog(fmt, ...) NSLog((@"%s [Line %d] "  fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__);

#else

#define ZKLog(...)

#endif

像素与尺寸的关系

[UIScreen mainScreen].scale

//当前版本

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

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

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

//当前语言

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

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000

#define Textsize(text, font, maxWith) [text length] > 0 ? [text \\

boundingRectWithSize:CGSizeMake(maxWith, MAXFLOAT) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) \\

attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil].size : CGSizeZero;

#else

#define Textsize(text, font, maxWith) [text length] > 0 ? [text \\

sizeWithFont:[UIFont systemFontOfSize:font] constrainedToSize:CGSizeMake(maxWith, MAXFLOAT)] : CGSizeZero;

#endif

// 大于等于IOS7

#define RC_MULTILINE_TEXTSIZE_GEIOS7(text, font, maxSize) [text length] > 0 ? [text \\

boundingRectWithSize:maxSize options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) \\

attributes:@{NSFontAttributeName:font} context:nil].size : CGSizeZero;

// 小于IOS7

#define RC_MULTILINE_TEXTSIZE_LIOS7(text, font, maxSize, mode) [text length] > 0 ? [text \\

sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero;

上一篇下一篇

猜你喜欢

热点阅读