zoukankan      html  css  js  c++  java
  • Swift3.0 创建工程常用的类、三方、以及扩展 1.5

    搭建项目常用的方法属性,欢迎追加

    三方:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, ‘8.0’
    use_frameworks!
    
    target 'swift' do 
    pod 'SwiftyJSON', '~> 3.0'
    pod 'MJExtension', '~> 3.0.13'
    pod 'MBProgressHUD', '~> 1.0.0'
    pod 'AFNetworking', '~> 3.1.0'
    pod 'SDWebImage', '~> 3.8.2'
    pod 'XMLReader', '~> 0.0.2'
    pod 'GDataXML-HTML', '~> 1.3.0'
    pod 'Reachability', '~> 3.2'
    pod 'FMDB', '~> 2.6.2'
    pod 'SDAutoLayout'
    pod 'Alamofire', '~> 4’
    
    
    
    end
    View Code

    扩展:

    1、MBProgressHUD-Extension  http://pan.baidu.com/s/1jIpAngM
    
    2、ToolExtension: 用十六进制颜色创建UIColor
    
    extension UIColor {
        
        static func Xrgb(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat) -> UIColor {
            return UIColor.init(red: r / 255,
                                green: g / 255,
                                blue: b / 255,
                                alpha: 1.0)
        }
        
        static func XcolorFromHex(_ Hex: UInt32) -> UIColor {
            return UIColor.init(red: CGFloat((Hex & 0xFF0000) >> 16) / 255.0,
                                green: CGFloat((Hex & 0xFF00) >> 8) / 255.0,
                                blue: CGFloat((Hex & 0xFF)) / 255.0,
                                alpha: 1.0)
        }
        
    }

    使用方法:

      let heigth = XiPhoneHeight(height: 80)
    
      let image = XImageName(name: "iamge")

    SwiftPCH.swift

    //适配高 宽
    func XiPhoneHeight(height:CGFloat) -> CGFloat {
        
        return UIScreen.main.bounds.size.height * (height / 1334.0)
        
    }
    
    
    func XiPhoneWidth(CGFloat) -> CGFloat {
        
        return UIScreen.main.bounds.size.width * (width / 750.0)
        
    }
    
    // 获取屏幕的 高宽
    func XScreeWidth() -> CGFloat {
        
        return UIScreen.main.bounds.size.width
    }
    
    func XScreenHeight() -> CGFloat {
        
        return UIScreen.main.bounds.size.height
    }
    
    
    
    //系统相关
    
    
    //系统iOS版本
    func XiOSVersion() -> String {
        
        return UIDevice.current.systemVersion
        
        
    }
    
    //判断系统版本是不是。。。
    func XiOSVersionOfString(string:String) -> Bool {
        
        if string.compare(UIDevice.current.systemVersion as String).rawValue == 0 {
            return true
        }else{
            
            return false
        }
        
        
    }
    
    //model
    func XiOSVersionModel() -> String {
        return UIDevice.current.model
    }
    
    
    // 需要给 地位 添加系统文件 不需要请注掉
    //定位
    
    
    //    let locationManager = CLLocationManager()
    //    var currentLocation:CLLocation
    //    var  lock = NSLock()
    
    //    locationManager.delegate = self
    //    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    //    locationManager.distanceFilter = 50
    //    locationManager.requestAlwaysAuthorization()
    //
    //
    //
    //    //委托传回定位,获取最后一个
    //    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    //        lock.lock()
    //        currentLocation = locations.last    //注意:获取集合中最后一个位置
    //        print("定位经纬度为:(currentLocation.coordinate.latitude)")
    //        //一直发生定位错误输出结果为0:原因是我输出的是currentLocation.altitude(表示高度的)而不是currentLoction.coordinate.latitude(这个才是纬度)
    //        print(currentLocation.coordinate.longitude)
    //        lock.unlock()
    //
    //    }
    //    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    //        print("定位出错拉!!(error)")
    //    }
    //
    //
    
    
    
    
    //属性方法
    
    //颜色
    //backgroundcolor
    func XbackgroundColor() -> UIColor {
        
        return UIColor.Xrgb(230, 230, 230)
    }
    
    func XClearColor() -> UIColor {
        return UIColor.clear
    }
    
    func XWhiteColor() -> UIColor {
        return UIColor.white
    }
    
    
    
    //图片相关
    
    //获取本地图片
    //    func ImageName(name:String) -> UIImage {
    //        return UIImage(named: name) as! String
    //    }
    
    func XImageData(data:Data) -> UIImage {
        return UIImage(data: data)!
    }
    
    
    //需要给Md5 创建桥接文件,不需要此方法 请注掉
    //数据处理
    func Xmd5String(str:String) -> String{
        let cStr = str.cString(using: String.Encoding.utf8);
        let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: 16)
        CC_MD5(cStr!,(CC_LONG)(strlen(cStr!)), buffer)
        let md5String = NSMutableString();
        for i in 0 ..< 16{
            md5String.appendFormat("%02x", buffer[i])
        }
        free(buffer)
        return md5String as String
    }
    
    
    
    
    
    
    
    
    //UI布局 label button
    
    //Label frame:上左 宽高
    func XlabelFrame(x:CGFloat,y:CGFloat,CGFloat,height:CGFloat,text:String,textcolor:UIColor,font:CGFloat,backgroundColor:UIColor) -> UILabel {
        
        let label = UILabel(frame: CGRect(x: x, y:y,  width, height:height))
        label.text = text
        label.textColor = textcolor
        label.font = UIFont.systemFont(ofSize: font)
        label.backgroundColor = backgroundColor
        
        
        return label
    }
    
    
    //无frame
    func Xlabel(text:String,textcolor:UIColor,font:CGFloat,backgroundColor:UIColor) -> UILabel {
        
        let label = UILabel()
        label.text = text
        label.textColor = textcolor
        label.font = UIFont.systemFont(ofSize: font)
        label.backgroundColor = backgroundColor
        
        
        return label
    }
    
    
    
    //UIbutton
    func XbuttonFrame(x:CGFloat,y:CGFloat,CGFloat,height:CGFloat,text:String,textcolor:UIColor,font:CGFloat,backgroundColor:UIColor,cornerRadius:CGFloat) -> UIButton {
        
        let button = UIButton(frame: CGRect(x: x, y:y,  width, height:height))
        button.setTitle(text, for: .normal)
        button.setTitleColor(textcolor, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: font)
        if cornerRadius>0 {
            button.backgroundColor = backgroundColor
            button.layer.cornerRadius = cornerRadius
        }
        
        button.layer.masksToBounds = true
        
        
        return button
    }
    
    //UIImageview
    func XimageViewFrame(x:CGFloat,y:CGFloat,CGFloat,height:CGFloat,name:String,backgroundColor:UIColor,cornerRadiu:CGFloat) -> UIImageView {
        
        let imageView = UIImageView(frame: CGRect(x: x, y:y,  width, height:height))
        imageView.image = UIImage(named:name)
        imageView.backgroundColor = backgroundColor
        if cornerRadiu>0 {
            imageView.layer.cornerRadius = cornerRadiu
            imageView.layer.masksToBounds = true
        }
        
        imageView.contentMode = .scaleAspectFit //保持比例
        
        
        return imageView
    }
  • 相关阅读:
    Docker容器彻底删除所有容器、删除所有镜像、删除所有卷、删除所有网络
    Fabric区块链浏览器启动报错Error : [ 'Explorer is closing due to channel name [%s] is already exist in DB'...]
    查看docker里面的Postgres数据库里面的信息
    将本地镜像推送到指定docker服务器
    linux 下 配置C++ 开发环境
    Go 发送邮件
    Ubuntu下使用nginx发布vue项目
    C++多线程之条件变量
    C/C++ 递归
    STL容器概述
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7244120.html
Copyright © 2011-2022 走看看