
swift
qq_27717857
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
swift 协议扩展基础
//定义一个得分记录协议 protocol Record{ var wins:Int{get} var losses:Int{get} //胜率 func winningPercent() -> Double } //乒乓球比赛记录 class TableTennisRecord:Record,CustomStringConvertible{原创 2016-12-13 10:48:55 · 394 阅读 · 0 评论 -
swift 字符串基础
1. swift字符串非常智能,不管是一个中文字符或一个英文字符还是一个表情都是一个character。本篇的例子都在playground上运行 var chinese = "字符串" chinese.characters.count -- 输出结果为 3 //一个cool表情 var cool = "\u{1F60E}" cool.characters.coun原创 2016-12-12 10:43:10 · 306 阅读 · 0 评论 -
'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a ...
swift3.0自定义UICollectionViewLayout 当数据改变collectionView.reloadData()时出现如下错误: 'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a cell with an index path tha原创 2017-04-21 11:13:21 · 1596 阅读 · 0 评论 -
swift3.0多列表格 行和列可以滚动的集合视图
项目地址:https://github.com/xjh19920000/CollectionTableView原创 2017-04-13 21:00:46 · 1332 阅读 · 0 评论 -
swift 可选项 "?" 和 "!"
1.可选项目的 解决“有” 和 “无”的问题 2.可选项定义 只能用" ?",表示变量可以为 nil ,或者有一个值 var mainVC: UIViewController? -> 只是定义,没有分配空间和初始值 3.可选项解包 (1). "!" 强行解包 目的是为了参与计算,但是存在风险,最好需要判断是否为nil(可以用 guard le原创 2017-03-24 12:01:20 · 651 阅读 · 0 评论 -
swift 去除tableView 多余行的方法
//去除tableView 多余行的方法 添加一个tableFooterView 后面多余行不再显示 tableView.tableFooterView = UIView()原创 2017-03-23 11:38:47 · 935 阅读 · 0 评论 -
swift3.0 圆环
最近公司新项目要用swift做ios,产品图上有个显示体重的圆环。刚学不久实在是不会写。于是找了几个用swift写的仪表盘稍作修改。先来一张效果图: 代码: import UIKit extension UIViewController { var bounds : CGRect { get { return view.bou原创 2017-03-28 19:38:33 · 1081 阅读 · 0 评论 -
swift 定时器
var cycyleTimer : Timer? // 添加定时器 fileprivate func addCycleTimer() { cycyleTimer = Timer(timeInterval: 1.0, target: self, selector: #selector(self.scrollToNext), userInfo: nil, repeats原创 2017-03-21 17:14:36 · 412 阅读 · 0 评论 -
swift3.0 浮点数四舍五入为整数
lroundf是一个全局函数,作用是将浮点数四舍五入转为整数。 var i = lroundf(23.50) //24 var j = lroundf(23.40) //23原创 2017-04-07 09:03:34 · 735 阅读 · 0 评论 -
swift 四分之一圆的弧线
使用 UIBezierPath 类的init(arcCenter center:CGPoint, radius:CGFloat, startAngle:CGFloat, endAngle:CGFloat, clockwise:Bool) 方法。 center 是圆心坐标,radius 是半径长度,startAngle 是起始点,endAngle 是终点,clockwise 是 true原创 2017-03-28 09:49:46 · 1571 阅读 · 0 评论 -
swift 扩展系统类的构造函数
1. 对系统类扩展构造函数只能扩展便利构造函数,也就是以convenience开头 convenience init(){ code } 2.在构造函数中必须明确调用一个设计的构造函数(使用self来调用的) 下面是一个扩展UIBarButtonItem的例子 extension UIBarButtonItem{ convenience ini原创 2016-12-15 15:21:45 · 546 阅读 · 0 评论 -
swift 获取一个数组中的最大值
func maxOneComparable>( _ seq:[T]) -> T{ assert(seq.count>0) return seq.reduce(seq[0]){ max($0, $1) } } maxOne([1,2,199,21,17,92,17]) //输出结果为:199 class Student:原创 2016-12-13 11:55:23 · 3549 阅读 · 0 评论 -
swift3.0 使用第三方加载cell的网络图片
pod 'AlamofireImage' import AlamofireImage func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell : RightSlideCell = tableVie原创 2017-05-15 09:21:34 · 478 阅读 · 0 评论