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

個人拖延癥太嚴重,一直沒好好學習Swift。受@Allen_朝輝啟發,決定每天寫個小項目來學習Swift。

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

Project 01 - SimpleStopWatch

Project 01 - SimpleStopWatch.gif

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

Project 02 - CustomFont

Project 02 - CustomFont.gif

1)自定義字體
2)項目中導入字體文件(注意:直接拖到項目中,Build Phases - Copy Bundle Resources 肯沒有自動包含,需要手動添加)
3)在info.plist中添加Fonts provided by application屬性,添加字體

image.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

Project 03 - PlayLocalVideo.gif

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

Project 04 - SnapChatMenu

Project 04 - SnapChatMenu.gif

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

Project 05 - CarouselEffect

Project 05 - CarouselEffect.gif

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

Project 06 - FindMyLocation

Project 06 - FindMyLocation.gif

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

Project 07 - PullToRefresh

Project 07 - PullToRefresh.gif

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

Project 08 - RandomGradientColor

Project 08 - RandomGradientColor.gif

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

Project 09 -ImageScroller.gif

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

Project 10 - VideoBackground

Project 10 - VideoBackground.gif

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

Project 11 - GradientTableView

Project 11 - GradientTableView.gif

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

Project 12 - LoginAnimation.gif

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容