自學 Swift - 三十天三十個 Swift 小項目(更新中...)

我的拖延症太嚴重,一直沒好好學習Swift。受@Allen_朝輝啓發,決定天天寫個小項目來學習Swift。git

項目代碼同步更新到github:項目地址github

Project 01 - SimpleStopWatch

clipboard.png

1)簡單的計時器
2)使用 Timer.scheduledTimer
3)開始,暫停,重置功能swift

Project 02 - CustomFont

clipboard.png

1)自定義字體
2)項目中導入字體文件(注意:直接拖到項目中,Build Phases - Copy Bundle Resources 肯沒有自動包含,須要手動添加)
3)在info.plist中添加Fonts provided by application屬性,添加字體
clipboard.png
4)使用如下代碼打印出字體名字數組

for family in UIFont.familyNames {
                    print("font-family:",family)
                    for font in UIFont.fontNames(forFamilyName: family) {
                        print("font-name:",font)
                    }
                }

Project 03 - PlayLocalVideo

clipboard.png

1)播放本地視頻
2)使用UITableView作個個視頻列表
3)import AVKit 使用AVPlayerViewController播放視頻app

Project 04 - SnapChatMenu

clipboard.png

1)模仿SnapChat樣式
2)左右兩個視圖是UIImageView
3)相機使用AVFoundation框架框架

Project 05 - CarouselEffect

clipboard.png

1)UICollectionView實現的卡片選擇
2)使用UIBlurEffect UIVisualEffectView 添加了模糊效果dom

Project 06 - FindMyLocation

clipboard.png

1)定位
2)在info.plist中添加 NSLocationWhenInUseUsageDescription
3)使用CoreLocation框架獲取當前位置ide

Project 07 - PullToRefresh

clipboard.png

1)使用UIRefreshControl實現的下拉刷新學習

Project 08 - RandomGradientColor

clipboard.png

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

clipboard.png

1)使用UIScrollView實現的圖片縮放功能

Project 10 - VideoBackground

clipboard.png

1)模仿spotyfi的登陸背景視頻播放
2)使用AVPlayer和AVPlayerLayer

Project 11 - GradientTableView

clipboard.png

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

clipboard.png

1)登陸界面的小動畫2)進入頁面的動畫使用UIView.animate3)點擊登陸按鈕使用的CAKeyframeAnimation

相關文章
相關標籤/搜索