在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学习仿照OC中的宏定义全部内容,希望文章能够帮你解决Swift学习仿照OC中的宏定义所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)