Swift学习仿照OC中的宏定义

在Swift中不需要去创建header文件,只需要创建一个类即可,什么也不用配置。下面是一些本人总结的一些常用的宏定义:

let GWIDTH = UIScreen.main.bounds.size.width

let GHEIGHT = UIScreen.main.bounds.size.height

let isIPhoneX: Bool = GHEIGHT == 812 ? true : false

/// iPhone4设备

let isIPhone4 = (max(UIScreen.main.bounds.size.width,UIScreen.main.bounds.height) < 568.0 ? true : false)

/// iPhone5设备

let isIPhone5 = (max(UIScreen.main.bounds.size.width,UIScreen.main.bounds.height) == 568.0 ? true : false)

/// iPhone6设备

let isIPhone6 = (max(UIScreen.main.bounds.size.width,UIScreen.main.bounds.height) == 667.0 ? true : false)

/// iPhone6Plus设备

let isIPhone6P = (max(UIScreen.main.bounds.size.width,UIScreen.main.bounds.height) == 736.0 ? true : false)


let GetAppInfo = Bundle.main.infoDictionary//当前app信息

let GetAppCurrentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")//获取当前版本号

let GetSystemVersion = UIDevice.current.systemVersion//获取设备系统号

let isIphone = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone ? true : false//iphone设备

let isIpad = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad ? true : false//ipad设备



//rgb

func COLORFROMRGB(r:CGFloat,_ g:CGFloat,_ b:CGFloat,alpha:CGFloat) -> UIColor

{

return UIColor(red: (r)/255.0,green: (g)/255.0,blue: (b)/255.0,alpha: alpha)

}

//十六进制颜色

func COLORFROM16(h:Int) ->UIColor {

return COLORFROMRGB(r: CGFloat(((h)>>16) & 0xFF),CGFloat(((h)>>8) & 0xFF),CGFloat((h) & 0xFF),alpha: 1.0)

}

相关文章

Swift 正式开源!Swift 团队很高兴宣布 Swift 开始开源新篇章。自从苹果发布 Swfit 编程语言,就成为了...
快,快,快!动动您的小手,分享给更多朋友! 苹果去年推出了全新的编程语言Swift,试图让iOS开发更简单...
开发者(KaiFaX) 面向开发者、程序员的专业平台! 和今年年初承诺的一样,苹果贴出了Swift语言的源码,...
本文由@Chun发表于Chun Tips :http://chun.tips/blog/2014/12/11/shi-yong-swift-gou-jian-zi-ding-yi...
本文由CocoaChina译者leon(社区ID)翻译 原文:THE RIGHT WAY TO WRITE A SINGLETON 在之前的帖子里聊过...
本文由CocoaChina译者leon(社区ID)翻译 原文:THE RIGHT WAY TO WRITE A SINGLETON 在之前的帖子里聊过...