搭建项目常用的方法属性,欢迎追加
使用方法:
let heigth = XSizeClass().iPhoneHeight(height: 80) let image = XAttributeClass().ImageName(name: "iamge")
SwiftPCH.swift
import Foundation import UIKit //尺寸大小 class XSizeClass: NSObject { //适配高 宽 func iPhoneHeight(height:CGFloat) -> CGFloat { return UIScreen.main.bounds.size.height * (height / 1334.0) } func iPhoneWidth(width:CGFloat) -> CGFloat { return UIScreen.main.bounds.size.width * (width / 750.0) } // 获取屏幕的 高宽 func ScreeWidth() -> CGFloat { return UIScreen.main.bounds.size.width } func ScreenHeight() -> CGFloat { return UIScreen.main.bounds.size.height } } //系统相关 class XSystemClass: NSObject { //系统iOS版本 func iOSVersion() -> String { return UIDevice.current.systemVersion } //判断系统版本是不是。。。 func iOSVersionOfString(string:String) -> Bool { if string.compare(UIDevice.current.systemVersion as String).rawValue == 0 { return true }else{ return false } } } //属性方法 class XAttributeClass:NSObject{ //userDefault func UserDefaultsSave(object:String , key:String) { UserDefaults.standard.set(object, forKey: key) } func UserDefaultsGet(key:String) -> String { return UserDefaults.standard.object(forKey: key) as! String } func UserDefaultsRemove(key:String) { UserDefaults.standard.removeObject(forKey: key) } //颜色 func ColorRGB(r:CGFloat,g:CGFloat,b:CGFloat) -> UIColor { return UIColor.init(colorLiteralRed: Float(r), green: Float(g), blue: Float(b), alpha: 1) } func ClearColor() -> UIColor { return UIColor.clear } func WhiteColor() -> UIColor { return UIColor.white } //图片相关 //获取本地图片 func ImageName(name:String) -> UIImage { return UIImage.init(named: name)! } func ImageData(data:Data) -> UIImage { return UIImage.init(data: data)! } }
时间: 2024-10-10 10:48:46