今天我們要建立UI為SwiftUI的專案,並實際來練習Path繪圖,由於SwiftUI還沒有時間深入的研究,因此先練習一個小題目(ref5)。
在兩年前有去台北上過彼得潘的課程,現在重頭開始學習iOS App開發,也可以接者練習網站上的一百道題目考驗(ref6),有許多題目都非常的有趣。
現在,我們馬上開始!
今天我們要建立Swift專案,並利用Path來描繪可愛的石虎,首先參考一下原圖
圖片來源: 南投縣友善石虎農作促進會
Day13 在Swift的世界中朗誦HelloWorld (1)
https://ithelp.ithome.com.tw/articles/10221914
// background
Image("Cat3")
.resizable()
.scaledToFit()
.frame(width: 300, height: 400, alignment: .bottom)
// MARK: - HeadLayer
Group {
Path { (path) in
path.move(to: CGPoint(x: 53, y: 100))
path.addQuadCurve(to: CGPoint(x: 66, y: 17), control:
CGPoint(x: 48, y: 50))
path.addQuadCurve(to: CGPoint(x: 119, y: 80), control:
CGPoint(x: 90, y: 30))
path.addLine(to: CGPoint(x: 164, y: 82))
path.addQuadCurve(to: CGPoint(x: 214, y: 13), control:
CGPoint(x: 178, y: 38))
path.addQuadCurve(to: CGPoint(x: 230, y: 96), control:
CGPoint(x: 234, y: 60))
path.addQuadCurve(to: CGPoint(x: 239, y: 193), control
CGPoint(x: 265, y: 138))
path.addQuadCurve(to: CGPoint(x: 170, y: 242), control
CGPoint(x: 235, y: 215))
path.addQuadCurve(to: CGPoint(x: 80, y: 230), control:
CGPoint(x: 130, y: 225))
path.addQuadCurve(to: CGPoint(x: 53, y: 100), control:
CGPoint(x: 5, y: 175))
path.closeSubpath()
}
.stroke(Color(red: 165/255, green: 113/255, blue: 80/255),
lineWidth:15)
Path { (path) in
path.move(to: CGPoint(x: 53, y: 100))
path.addQuadCurve(to: CGPoint(x: 66, y: 17), control:
CGPoint(x: 48, y: 50))
path.addQuadCurve(to: CGPoint(x: 119, y: 80), control:
CGPoint(x: 90, y: 30))
path.addLine(to: CGPoint(x: 164, y: 82))
path.addQuadCurve(to: CGPoint(x: 214, y: 13), control:
CGPoint(x: 178, y: 38))
path.addQuadCurve(to: CGPoint(x: 230, y: 96), control:
CGPoint(x: 234, y: 60))
path.addQuadCurve(to: CGPoint(x: 239, y: 193), control
CGPoint(x: 265, y: 138))
path.addQuadCurve(to: CGPoint(x: 170, y: 242), control
CGPoint(x: 235, y: 215))
path.addQuadCurve(to: CGPoint(x: 80, y: 230), control:
CGPoint(x: 130, y: 225))
path.addQuadCurve(to: CGPoint(x: 53, y: 100), control:
CGPoint(x: 5, y: 175))
path.closeSubpath()
}
.fill(Color(red: 205/255, green: 154/255, blue: 114/255))
}
可以看到上方的石虎抱抱,是我們用Path所描繪出來的。而下方的背景圖,則是原圖
在今天的文章裡,我們練習建立了SwiftUI專案,
也練習了SwiftUI的使用Path來繪製可愛的石虎抱抱。
今天的內容就到這邊,感謝讀者們的閱讀。
https://github.com/chiron-wang/IT30_11
彼得潘的 Swift iOS App 開發問題解答集
https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86
iOS 13 & Swift 5 - The Complete iOS App Development Bootcamp - Angela Yu
https://www.udemy.com/course/ios-13-app-development-bootcamp/
深入淺出 iPhone 開發 (使用 Swift4) - WeiWei
https://www.udemy.com/course/iphone-swift4/
心智圖軟體Xmind
https://www.xmind.net/
俄羅斯插畫家親繪石虎送台灣 有望登上彩繪列車!
https://udn.com/news/story/7266/4013861
Swift 起步走 集合型別
https://itisjoe.gitbooks.io/swiftgo/content/ch1/collection_types.html