個人拖延癥太嚴重,一直沒好好學習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