常用的宏定義

//獲取屏幕 寬度、高度

//寬度

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

//高度

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

// rgb顏色轉(zhuǎn)換(16進(jìn)制->10進(jìn)制)

#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

像素與尺寸的關(guān)系

[UIScreen mainScreen].scale

//當(dāng)前版本

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

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

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

//當(dāng)前語言

#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;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容