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

三方:

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

扩展:

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 / ,
green: g / ,
blue: b / ,
alpha: 1.0)
} static func XcolorFromHex(_ Hex: UInt32) -> UIColor {
return UIColor.init(red: CGFloat((Hex & 0xFF0000) >> ) / 255.0,
green: CGFloat((Hex & 0xFF00) >> ) / 255.0,
blue: CGFloat((Hex & 0xFF)) / 255.0,
alpha: 1.0)
} }

使用方法:

  let heigth = XiPhoneHeight(height: )

  let image = XImageName(name: "iamge")

SwiftPCH.swift

//适配高 宽
func XiPhoneHeight(height:CGFloat) -> CGFloat { return UIScreen.main.bounds.size.height * (height / 1334.0) } func XiPhoneWidth(width: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 == {
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(, , )
} 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: )
CC_MD5(cStr!,(CC_LONG)(strlen(cStr!)), buffer)
let md5String = NSMutableString();
for i in ..< {
md5String.appendFormat("%02x", buffer[i])
}
free(buffer)
return md5String as String
} //UI布局 label button //Label frame:上左 宽高
func XlabelFrame(x:CGFloat,y:CGFloat,width:CGFloat,height:CGFloat,text:String,textcolor:UIColor,font:CGFloat,backgroundColor:UIColor) -> UILabel { let label = UILabel(frame: CGRect(x: x, y:y, width: 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,width:CGFloat,height:CGFloat,text:String,textcolor:UIColor,font:CGFloat,backgroundColor:UIColor,cornerRadius:CGFloat) -> UIButton { let button = UIButton(frame: CGRect(x: x, y:y, width: width, height:height))
button.setTitle(text, for: .normal)
button.setTitleColor(textcolor, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: font)
if cornerRadius> {
button.backgroundColor = backgroundColor
button.layer.cornerRadius = cornerRadius
} button.layer.masksToBounds = true return button
} //UIImageview
func XimageViewFrame(x:CGFloat,y:CGFloat,width:CGFloat,height:CGFloat,name:String,backgroundColor:UIColor,cornerRadiu:CGFloat) -> UIImageView { let imageView = UIImageView(frame: CGRect(x: x, y:y, width: width, height:height))
imageView.image = UIImage(named:name)
imageView.backgroundColor = backgroundColor
if cornerRadiu> {
imageView.layer.cornerRadius = cornerRadiu
imageView.layer.masksToBounds = true
} imageView.contentMode = .scaleAspectFit //保持比例 return imageView
}

Swift3.0 创建工程常用的类、三方、以及扩展 1.5的更多相关文章

  1. cocos2d-x 3.0 创建工程的模板

    将下面的代码拷贝到文本文件中,重命名文件为 cocos3.0创建工程.bat @echo off echo -------------------------create project with p ...

  2. swift3.0 创建经典界面的九宫图

    网络上很多例子都是早期的 Object-C的效果,现在用到Swift3.0开发,故把网络上的例子翻译过来,达到基本的效果.可是现在这个还不算很满意,再下次继续进行优化 override func vi ...

  3. swift3.0 创建一个app引导页面

    swift毕竟不像是oc ,第三方的框架很多,更何况是3.0,自己动手写了个引导页面,看得上我代码的麻友可以拿去用 引导页面有三个部分构成,scrollview用语切换引导视图,pageControl ...

  4. 青瓷qici - H5小游戏 抽奖机 0 创建工程

    安装运行平台需要nodejs,具体方法请参照官方说明文档. 运行后打开了一个空空的窗口. 首先我们进行工程设置,菜单>工程>设置 菜单里面设置我们游戏的名称,到时候会显示在游戏的title ...

  5. cocos2d-x.0创建工程

    $ python create-multi-platform-projects.py -p PompaDroid -k cn.philon.pompadroid -l cpp

  6. Swift3.0变化分享

    Swift 3.0 做出的改变很大,在这篇文章中,我将尽我所能,利用代码样例给大家解释Swift 3.0最重要(要命)的改变,希望大家能够做好升级Swift 3.0 的准备.Swift 3.0的改变不 ...

  7. swift3.0变化总结

    Swift 3.0 做出的改变很大,在这篇文章中,我将尽我所能,利用代码样例给大家解释Swift 3.0最重要(要命)的改变,希望大家能够做好升级Swift 3.0 的准备.Swift 3.0的改变不 ...

  8. Swift2.3 --> Swift3.0 的变化

    Swift3.0语法变化 首先和大家分享一下学习新语法的技巧: 用Xcode8打开自己的Swift2.3的项目,选择Edit->Convert->To Current Swift Synt ...

  9. Swift3.0语法变化

    写在前面 首先和大家分享一下学习新语法的技巧:用Xcode8打开自己的Swift2.3的项目,选择Edit->Convert->To Current Swift Syntax- 让Xcod ...

随机推荐

  1. bootstrap导航栏.nav与.navbar区别

    刚刚看了bootstrap的导航栏,发现有点弄混了,现在来整理一下: 一.简单的ul,li组成的导航: <ul class="nav nav-pills justify-content ...

  2. 基于SwiperJs的H5/移动端下拉刷新上拉加载更多的效果

    最早时,公司的H5项目中曾用过点击一个"加载更多"的DOM元素来实现分页的功能,后来又用过网上有人写的一个上拉加载更多的插件,那个插件是页面将要滚动到底部时就自动请求数据并插入到页 ...

  3. LuaJavaBridge - Lua 与 Java 互操作的简单解决方案

    http://dualface.github.io/blog/2013/01/01/call-java-from-lua/ 最近在游戏里要集成中国移动的 SDK,而这些 SDK 都是用 Java 编写 ...

  4. 《java.util.concurrent 包源码阅读》18 Exchanger

    Exchanger可以看做双向数据传输的SynchronousQueue,即没有生产者和消费者之分,任意两个线程都可以交换数据. 在JDK5中Exchanger被设计成一个容量为1的容器,存放一个等待 ...

  5. MatlabR2015b用了一段时间之后需要重新激活

    问题描述:MatlabR2015b安装成功,用了一段时间之后需要重新激活,按照http://www.cr173.com/soft/490645.html教程,无法激活成功,卸载重新安装也不行. 解决方 ...

  6. 深度解析continue,break和return

    continue,break和return是Java中的关键字,在方法体内的流程控制中使用频率较高. 在现实中,经常会有同学在使用中产生混淆,从而使得流程控制语句发生混乱.在这里,我结合个人的使用经历 ...

  7. 基于ESXI6.5的服务器基本配置(HP DL388 Gen 9)

    最近一段时间由于做毕业设计的原因,一直处于忙碌状态,刚做完毕业设计,导师处于项目的原因,买了一台惠普服务器(人民币1.7万),服务器自带的内存仅有16 G,硬盘也就只有600G,而且磁盘还做了raid ...

  8. Nginx的知识分享,继续上次的分享

    5. Nginx配置文件精讲二 #这里为后端服务器wugk应用集群配置,根据后端实际情况修改即可,tdt_wugk为负载均衡名称,可以任意指定 #但必须跟vhosts.conf虚拟主机的pass段一致 ...

  9. Linux常用基础命令

    一.系统目录结构 约定俗成:   bin (binaries)存放二进制可执行文件   sbin (super user binaries)存放二进制可执行文件,只有root才能访问   etc (e ...

  10. 5、C#基础 - C#的值类型

    1.C#的值类型 有几个特点: 存储在栈里 基于值类型的变量直接包含值(值类型存储实际值). 将一个值类型变量赋给另一个值类型变量时,将复制包含的值. 这与引用类型变量的赋值不同,引用类型变量的赋值只 ...