个人拖延症太严重,一直没好好学习Swift。受@Allen_朝辉启发,决定每天写个小项目来学习Swift。
项目代码同步更新到github:项目地址
Project 01 - SimpleStopWatch

1)简单的计时器
2)使用 Timer.scheduledTimer
3)开始,暂停,重置功能
Project 02 - CustomFont

1)自定义字体
2)项目中导入字体文件(注意:直接拖到项目中,Build Phases - Copy Bundle Resources 肯没有自动包含,需要手动添加)
3)在info.plist中添加Fonts provided by application属性,添加字体

4)使用以下代码打印出字体名字
for family in UIFont.familyNames {
print("font-family:",family)
for font in UIFont.fontNames(forFamilyName: family) {
print("font-name:",font)
}
}
Project 03 - PlayLocalVideo

1)播放本地视频
2)使用UITableView做个个视频列表
3)import AVKit 使用AVPlayerViewController播放视频
Project 04 - SnapChatMenu

1)模仿SnapChat样式
2)左右两个视图是UIImageView
3)相机使用AVFoundation框架
Project 05 - CarouselEffect

1)UICollectionView实现的卡片选择
2)使用UIBlurEffect UIVisualEffectView 添加了模糊效果
Project 06 - FindMyLocation

1)定位
2)在info.plist中添加 NSLocationWhenInUseUsageDescription
3)使用CoreLocation框架获取当前位置
Project 07 - PullToRefresh

1)使用UIRefreshControl实现的下拉刷新
Project 08 - RandomGradientColor

1)使用CAGradientLayer实现的随机渐变背景色
CAGradientLayer的坐标起点是左上角(0,0)终点是右下角(1,1)
CAGradientLayer属性:
colors
var colors: [AnyObject]?
一个包含CGColor的数组,规定所有的梯度所显示的颜色,默认为nil
locations
var locations: [NSNumber]?
一个内部是NSNumber的可选数组,规定所有的颜色梯度的区间范围,选值只能在0到1之间,并且数组的数据必须单增,默认值为nil
endPoint
var endPoint: CGPoint
终点坐标
startPoint
var startPoint: CGPoint
与endPoint相互对应,起点坐标
type
var type:String
绘制类型,默认值是axial,也就是线性绘制,各个颜色阶层直接的变化是线性的
Project 09 -ImageScroller

1)使用UIScrollView实现的图片缩放功能
Project 10 - VideoBackground

1)模仿spotyfi的登录背景视频播放
2)使用AVPlayer和AVPlayerLayer
Project 11 - GradientTableView

1)渐变色TableView
2)根据行数计算颜色
let color = CGFloat(indexPath.row) / CGFloat(self.datas.count) * 0.8
cell.backgroundColor = UIColor.init(red: 0, green: color, blue: 1.0, alpha: 1.0)
Project 12 - LoginAnimation

1)登录界面的小动画
2)进入页面的动画使用UIView.animate
3)点击登录按钮使用的CAKeyframeAnimation
网友评论