<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ChingWen on Medium]]></title>
        <description><![CDATA[Stories by ChingWen on Medium]]></description>
        <link>https://medium.com/@chingwenlo?source=rss-e6a184b99840------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rktiRiSYQZjCUTmh</url>
            <title>Stories by ChingWen on Medium</title>
            <link>https://medium.com/@chingwenlo?source=rss-e6a184b99840------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:04:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chingwenlo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[學習記錄#搭配 sketch & zeplin 製作 iOS 的健康 App 和 App Store 畫面]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E6%90%AD%E9%85%8D-sketch-zeplin-%E8%A3%BD%E4%BD%9C-ios-%E7%9A%84%E5%81%A5%E5%BA%B7-app-%E5%92%8C-app-store-%E7%95%AB%E9%9D%A2-14ebcc76ea6b?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/14ebcc76ea6b</guid>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Sun, 07 Feb 2021 14:16:15 GMT</pubDate>
            <atom:updated>2021-02-07T14:16:15.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qp-eqHlNwhvFsfjx" /><figcaption>Photo by <a href="https://unsplash.com/@jjying?utm_source=medium&amp;utm_medium=referral">JJ Ying</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>模仿 iOS Health Data &amp; App Store 畫面</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*sv15h3EP6f9h30pRClMO8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*ZqX-bPfPOdlKbtXlTmG6PQ.png" /></figure><p><strong><em>1 .下載 Sketch App</em></strong></p><p><a href="https://www.sketch.com/">Sketch · Design, prototype, collaborate and handoff</a></p><p><strong><em>2 .下載 iOS 11 &amp; iOS 14 畫面的 sketch 檔，裡面包含準備製作的健康 App 和 App Store 畫面。</em></strong></p><p><a href="https://iosdesignkit.io/ios-11-gui/">iOS 11 GUI for iPhone X and iPhone 8</a></p><p><strong><em>3. 安裝 San Francisco 字型檔。</em></strong></p><p><a href="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/%E5%AE%89%E8%A3%9D-san-francisco-%E5%AD%97%E5%9E%8B%E6%AA%94-%E8%AE%93-sketch-%E9%A1%AF%E7%A4%BA%E7%9A%84-app-%E7%95%AB%E9%9D%A2%E4%B8%8D%E5%86%8D%E8%B7%91%E7%89%88-64aad467d757">安裝 San Francisco 字型檔，讓 sketch 顯示的 App 畫面不再跑版</a></p><p><strong><em>4.下載 Mac 版的 Zeplin。</em></strong></p><p><a href="https://support.zeplin.io/en/articles/244698-downloading-mac-and-windows-apps">Downloading Mac and Windows apps</a></p><h3>~開始模仿~</h3><h3><strong>完成畫面</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*9gHRTbNV_sridEpSt3v4QQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*W8CIqhog4WL1dDPPzTJ_Pw.png" /></figure><p>參考資料:</p><p><a href="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/%E6%90%AD%E9%85%8D-sketch-zeplin-%E8%A3%BD%E4%BD%9C-ios-%E7%9A%84%E5%81%A5%E5%BA%B7-app-%E7%95%AB%E9%9D%A2-b6f077b5a023">搭配 sketch &amp; zeplin 製作 iOS 的健康 App 和 App Store 畫面</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14ebcc76ea6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E6%90%AD%E9%85%8D-sketch-zeplin-%E8%A3%BD%E4%BD%9C-ios-%E7%9A%84%E5%81%A5%E5%BA%B7-app-%E5%92%8C-app-store-%E7%95%AB%E9%9D%A2-14ebcc76ea6b">學習記錄#搭配 sketch &amp; zeplin 製作 iOS 的健康 App 和 App Store 畫面</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#在 Xcode playground 使用第三方套件]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%9C%A8-xcode-playground-%E4%BD%BF%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E5%A5%97%E4%BB%B6-5a11b0891036?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a11b0891036</guid>
            <category><![CDATA[spm]]></category>
            <category><![CDATA[playground]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 09:57:23 GMT</pubDate>
            <atom:updated>2021-02-01T09:57:23.563Z</atom:updated>
            <content:encoded><![CDATA[<p>目的:學習使用SPM 加入的畫圖套件</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*56-q5Bo4EhNKu7Qp" /><figcaption>Photo by <a href="https://unsplash.com/@kobuagency?utm_source=medium&amp;utm_medium=referral">KOBU Agency</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><strong><em>1.建立新專案</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FCBUtIMFJggfKCyesj8xA.png" /></figure><blockquote>2.<strong><em>點選專案檔，選擇 Project 下的專案，然後切換到 Swift Packages 頁面。</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hmbHg-cz-4ygnyTdgKrs-Q.png" /></figure><blockquote>3.<strong><em>點選左下角的 + 加入套件(package)。</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5i5l5Pk142NpGkjGcYkFug.png" /></figure><blockquote>4.<strong><em>複製 </em>SwiftyDraw<em> 的 GitHub 網址，將它輸入在 Enter package repository URL 的框框裡。</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6XE-Zk_SMO0uo1lLlC3I1w.png" /></figure><p>點選 Next。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8M5-TtD2blf3O1Ycptu2Ew.png" /><figcaption>Up to Next Minor 表示只考慮更新第三個數字改動的版本</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBnXog5TZ8TujFd8x95BSA.png" /></figure><p>點選 Finish，即可完成套件的安裝。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_joPiZ1yaTMJ6uBX1fdCg.png" /></figure><blockquote><strong>5.套件完成安裝後，Swift Packages 下的套件列表將出現 SwiftyDraw 的相關資訊。</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XGDqRib7hdl0UT_fp_r-A.png" /></figure><blockquote><strong><em>6. 在程式裡使用 </em>SwiftyDraw<em>。</em></strong></blockquote><pre>import UIKit<br>import SwiftyDraw<br>import PlaygroundSupportlet drawView = SwiftyDrawView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) //繪圖框架<br>drawView.brush.color = Color(UIColor(red: 1, green: 1, blue: 0, alpha: 1)) //顏色<br>drawView.brush.width = 10 //線寬度 <br>PlaygroundPage.current.liveView = drawView</pre><p>畫出美麗的太陽</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*7aV8WYcC78AMVicDUUnNww.png" /></figure><p>參考資料:</p><p><a href="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/%E5%9C%A8-xcode-playground-%E4%BD%BF%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E5%A5%97%E4%BB%B6-7709e3c8b6f">在 Xcode playground 使用第三方套件</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a11b0891036" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%9C%A8-xcode-playground-%E4%BD%BF%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E5%A5%97%E4%BB%B6-5a11b0891036">學習記錄#在 Xcode playground 使用第三方套件</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#Data Visualization 練習]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-data-visualization-%E7%B7%B4%E7%BF%92-cba23ba30da9?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/cba23ba30da9</guid>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 02:28:44 GMT</pubDate>
            <atom:updated>2021-01-28T02:28:44.091Z</atom:updated>
            <content:encoded><![CDATA[<p>目的: 學習使用 API 製作圖表。</p><h3>基礎題</h3><p>題目來源:<br>Develop in Swift Explorations 裡 2–2 Play With Programs 的 Data Visualization。</p><p><a href="https://books.apple.com/tw/book/develop-in-swift-explorations/id1511184149?l=en">‎Develop in Swift Explorations</a></p><p>下載電子書 Develop in Swift Explorations 後，點選以下頁面的 Download student materilas 下載書本提供的範例。(第 11 頁)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBH7d0VL9OLApr6wSpXzsw.png" /></figure><p>打開 Data Visualization.playground 後，照著檔案裡的說明操作。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7i2wHqYREeQCWyAWs3Steg.png" /></figure><p>圓餅圖(Pic Chart)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHqnnma0DZcZ37lGPGtEuA.png" /></figure><p>長條圖(Bar Chart)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YBwlPYP2RioD-qdLd84Diw.png" /></figure><p>散布圖(scatter plot)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjAzXt5OKZn3HBS7CrLLEA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cba23ba30da9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-data-visualization-%E7%B7%B4%E7%BF%92-cba23ba30da9">學習記錄#Data Visualization 練習</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#利用 UIBezierPath 實現圓環進度條，甜甜圈圖表 & 圓餅圖]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%88%A9%E7%94%A8-uibezierpath-%E5%AF%A6%E7%8F%BE%E5%9C%93%E7%92%B0%E9%80%B2%E5%BA%A6%E6%A2%9D-%E7%94%9C%E7%94%9C%E5%9C%88%E5%9C%96%E8%A1%A8-%E5%9C%93%E9%A4%85%E5%9C%96-42c5090a787e?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/42c5090a787e</guid>
            <category><![CDATA[progress-ring]]></category>
            <category><![CDATA[donut-chart]]></category>
            <category><![CDATA[pie-charts]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 02:27:28 GMT</pubDate>
            <atom:updated>2021-01-28T02:27:28.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*takwm6AY1HPM0a7Jb5Lbgw.png" /><figcaption>甜甜圈圖表上標示文字</figcaption></figure><h3>圓環進度條(circular progress ring)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*knYQx06aRe36wdAr_lTNPg.png" /></figure><pre><strong>let</strong> aDegree = CGFloat.pi / 180  // 每度</pre><pre><strong>let</strong> lineWidth: CGFloat = 20  // 線條（內徑）寬度</pre><pre><strong>let</strong> radius: CGFloat = 80  // 圓心的距離</pre><pre><strong>let</strong> startDegree: CGFloat = 270   // 起點</pre><pre><strong>let</strong> percentage: CGFloat = 30 //百分比</pre><pre>//繪製一個圓形當底</pre><pre><strong>let</strong> circlePath = UIBezierPath(ovalIn: CGRect(x: lineWidth, y: lineWidth, width: radius*2, height: radius*2))</pre><pre><strong>let</strong> circleLayer = CAShapeLayer()</pre><pre>circleLayer.path = circlePath.cgPath</pre><pre>circleLayer.strokeColor = UIColor.gray.cgColor  //線條顏色</pre><pre>circleLayer.lineWidth = lineWidth  //線條粗細</pre><pre>circleLayer.fillColor = UIColor.clear.cgColor  //背景顏色</pre><pre>//繪製另一個百分比圓形</pre><pre><strong>let</strong> percentagePath = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * startDegree, endAngle: aDegree * (startDegree + 360 * percentage / 100), clockwise: <strong>true</strong>)</pre><pre><strong>let</strong> percentageLayer = CAShapeLayer()</pre><pre>percentageLayer.path = percentagePath.cgPath</pre><pre>percentageLayer.strokeColor  = UIColor(red: 1, green: 1, blue: 0, alpha: 1).cgColor   //線條顏色</pre><pre>percentageLayer.lineWidth = lineWidth  //線條粗細</pre><pre>percentageLayer.lineCap = .round //調整線條端點的形狀</pre><pre>percentageLayer.fillColor = UIColor.clear.cgColor  //背景顏色</pre><pre>//顯示數值</pre><pre><strong>let</strong> label = UILabel(frame: CGRect(x: 0, y: 0, width: 2*(radius+lineWidth), height: 2*(radius+lineWidth)))</pre><pre>label.textAlignment = .center</pre><pre>label.text = &quot;\(percentage)%&quot;</pre><pre><strong>let</strong> view = UIView(frame: label.frame)</pre><pre>view.layer.addSublayer(circleLayer)</pre><pre>view.layer.addSublayer(percentageLayer)</pre><pre>view.addSubview(label)</pre><pre>view</pre><p>關於圓上的角度，可參考以下圖片的說明。一般常見的圓環進度條都是從 270 度的地方開始，因此我們以它為起點設定 startAngle，endAngle 則用 270 再加上 360 * percentage / 100 得到終點所在的角度。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-rDqOlkw-HkqRZex5lpcw.png" /></figure><h3>甜甜圈圖表(donut chart)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*fKaP_uGAWK8Htn-ZEzr30w.png" /></figure><pre><strong>let</strong> aDegree = CGFloat.pi / 180  // 每度</pre><pre><strong>let</strong> lineWidth: CGFloat = 40  // 線條（內徑）寬度</pre><pre><strong>let</strong> radius: CGFloat = 40  // 圓心的距離</pre><pre><strong>var</strong> startDegree: CGFloat = 270  // 起點</pre><pre><strong>let</strong> view = UIView(frame: CGRect(x: 0, y: 0, width: 2*(radius+lineWidth), height: 2*(radius+lineWidth))) //做一個View長寬=(radius+lineWidth)</pre><pre>view.backgroundColor = .white // 背景色</pre><pre><strong>var</strong> percentages: [CGFloat] = [30, 30, 40]  //百分比值</pre><pre>//將percentages的值帶入</pre><pre><strong>for</strong> percentage <strong>in</strong> percentages {</pre><pre><strong>let</strong> endDegree = startDegree + 360 * percentage / 100 //終點所在的角度</pre><pre><strong>let</strong> percentagePath = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * startDegree, endAngle: aDegree * endDegree, clockwise: <strong>true</strong>)</pre><pre><strong>let</strong> percentageLayer = CAShapeLayer()</pre><pre>percentageLayer.path = percentagePath.cgPath</pre><pre>percentageLayer.strokeColor  = UIColor(red: CGFloat.random(in: 0...1), green: CGFloat.random(in: 0...1), blue: CGFloat.random(in: 0...1), alpha: 1).cgColor //隨機出色</pre><pre>percentageLayer.lineWidth = lineWidth  //線條粗細</pre><pre>percentageLayer.fillColor = UIColor.clear.cgColor //背景顏色</pre><pre>view.layer.addSublayer(percentageLayer)</pre><pre>startDegree = endDegree // 終點的度數 = 下次起點度數</pre><pre>}</pre><pre>view</pre><h3>甜甜圈圖表上標示文字</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*RK1XwH9vtWc-DZzNXjBiTA.png" /></figure><pre>//計算圓弧中心的角度<br><strong>let</strong> textCenterDegree = startDegree + 360 * percentage / 2 / 100</pre><pre><strong>let</strong> textPath = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * textCenterDegree, endAngle: aDegree * textCenterDegree, clockwise: <strong>true</strong>)</pre><pre>//做一個label<br><strong>let</strong> label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30))</pre><pre>label.backgroundColor = UIColor.systemYellow //背景</pre><pre>label.font = UIFont.systemFont(ofSize: 12) //字體大小</pre><pre>label.text = &quot;\(percentage)%&quot;</pre><pre>label.sizeToFit() //讓文字的frame自適應內容大小</pre><pre>label.center = textPath.currentPoint //label 的中心座標</pre><p>解答寫的好漂亮，但不知道如何改成限定顯示顏色...只好來一層一層加上去</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*EMmgzf5bFI268EoHzgv7lw.png" /><figcaption>三元色</figcaption></figure><pre><strong>let</strong> aDegree = CGFloat.pi / 180  // 每度</pre><pre><strong>let</strong> lineWidth: CGFloat = 40  // 線條（內徑）寬度</pre><pre><strong>let</strong> radius: CGFloat = 40  // 圓心的距離</pre><pre><strong>var</strong> startDegree: CGFloat = 270  // 起點</pre><pre><strong>let</strong> percentage: CGFloat = 20 //first百分比</pre><pre><strong>let</strong> percentage1: CGFloat = 50 //second百分比</pre><pre><strong>let</strong> percentage2: CGFloat = 30 //three百分比</pre><pre><strong>let</strong> view = UIView(frame: CGRect(x: 0, y: 0, width: 2*(radius+lineWidth), height: 2*(radius+lineWidth))) //做一個View長寬=(radius+lineWidth)</pre><pre>view.backgroundColor = .white // 背景色</pre><pre>//畫第一個百分比</pre><pre><strong>let</strong> percentagePath = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * startDegree, endAngle: aDegree * (startDegree + 360 * percentage / 100), clockwise: <strong>true</strong>)</pre><pre><strong>let</strong> percentageLayer = CAShapeLayer()</pre><pre>percentageLayer.path = percentagePath.cgPath</pre><pre>percentageLayer.strokeColor  = UIColor(red: 1, green: 0, blue: 0, alpha: 1).cgColor</pre><pre>percentageLayer.lineWidth = lineWidth  //線條粗細</pre><pre>percentageLayer.fillColor = UIColor.clear.cgColor //背景顏色</pre><pre>//畫第二個百分比</pre><pre><strong>let</strong> percentagePath1 = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * (startDegree + 360 * percentage / 100), endAngle: aDegree * ((startDegree + 360 * percentage / 100) + 360 * percentage1 / 100), clockwise: <strong>true</strong>)</pre><pre><strong>let</strong> percentageLayer1 = CAShapeLayer()</pre><pre>percentageLayer1.path = percentagePath1.cgPath</pre><pre>percentageLayer1.strokeColor  = UIColor(red: 1, green: 1, blue: 0, alpha: 1).cgColor</pre><pre>percentageLayer1.lineWidth = lineWidth  //線條粗細</pre><pre>percentageLayer1.fillColor = UIColor.clear.cgColor //背景顏色</pre><pre>//畫第三個百分比</pre><pre><strong>let</strong> percentagePath2 = UIBezierPath(arcCenter: CGPoint(x: lineWidth + radius, y: lineWidth + radius), radius: radius, startAngle: aDegree * ((startDegree + 360 * percentage / 100) + 360 * percentage1 / 100), endAngle: aDegree * startDegree, clockwise: <strong>true</strong>)</pre><pre><strong>let</strong> percentageLayer2 = CAShapeLayer()</pre><pre>percentageLayer2.path = percentagePath2.cgPath</pre><pre>percentageLayer2.strokeColor  = UIColor(red: 0, green: 0, blue: 1, alpha: 1).cgColor</pre><pre>percentageLayer2.lineWidth = lineWidth  //線條粗細</pre><pre>percentageLayer2.fillColor = UIColor.clear.cgColor //背景顏色</pre><pre>view.layer.addSublayer(percentageLayer)</pre><pre>view.layer.addSublayer(percentageLayer1)</pre><pre>view.layer.addSublayer(percentageLayer2)</pre><pre>view</pre><h3>圓餅圖(pie chart)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*8H3z1Vp7Xu35jQQ5ncCxuQ.png" /></figure><pre><strong>let</strong> aDegree = CGFloat.pi / 180  // 每度</pre><pre><strong>let</strong> radius: CGFloat = 40  // 圓心的距離</pre><pre><strong>var</strong> startDegree: CGFloat = 270  // 起點</pre><pre><strong>let</strong> view = UIView(frame: CGRect(x: 0, y: 0, width: 2*(radius), height: 2*(radius))) //做一個View</pre><pre>view.backgroundColor = .white // 背景色</pre><pre><strong>var</strong> percentages: [CGFloat] = [20,20,30,30]  //百分比值</pre><pre>//將percentages的值帶入</pre><pre><strong>for</strong> percentage <strong>in</strong> percentages {</pre><pre><strong>let</strong> endDegree = startDegree + 360 * percentage / 100 //終點所在的角度</pre><pre><strong>let</strong> percentagePath = UIBezierPath()</pre><pre>percentagePath.move(to: view.center) //移動到圓心</pre><pre>percentagePath.addArc(withCenter: view.center, radius: radius, startAngle: aDegree * startDegree, endAngle: aDegree * endDegree, clockwise: <strong>true</strong>) //畫圓弧</pre><pre><strong>let</strong> percentageLayer = CAShapeLayer()</pre><pre>percentageLayer.path = percentagePath.cgPath</pre><pre>percentageLayer.fillColor  = UIColor(red: CGFloat.random(in: 0...1), green: CGFloat.random(in: 0...1), blue: CGFloat.random(in: 0...1), alpha: 1).cgColor //隨機出色</pre><pre>view.layer.addSublayer(percentageLayer)</pre><pre>startDegree = endDegree // 終點的度數 = 下次起點度數</pre><pre>}</pre><pre>view</pre><h3>最後就在圓餅圖(pie chart)上也要標示文字</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*1BxilbjGWRmoSIW0jFpr8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*bwaGQ4UA5Mfb75vZMQuNjw.png" /></figure><p>參考資料:</p><p><a href="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/%E5%88%A9%E7%94%A8-uibezierpath-%E5%AF%A6%E7%8F%BE%E5%9C%93%E7%92%B0%E9%80%B2%E5%BA%A6%E6%A2%9D-%E7%94%9C%E7%94%9C%E5%9C%88%E5%9C%96%E8%A1%A8-%E5%9C%93%E9%A4%85%E5%9C%96-6c9ac4f6ed01">利用 UIBezierPath 實現圓環進度條，甜甜圈圖表 &amp; 圓餅圖</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42c5090a787e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%88%A9%E7%94%A8-uibezierpath-%E5%AF%A6%E7%8F%BE%E5%9C%93%E7%92%B0%E9%80%B2%E5%BA%A6%E6%A2%9D-%E7%94%9C%E7%94%9C%E5%9C%88%E5%9C%96%E8%A1%A8-%E5%9C%93%E9%A4%85%E5%9C%96-42c5090a787e">學習記錄#利用 UIBezierPath 實現圓環進度條，甜甜圈圖表 &amp; 圓餅圖</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#利用 UIBezierPath 設計特別形狀的圖片 — 比方斜邊 & 愛心]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%88%A9%E7%94%A8-uibezierpath-%E8%A8%AD%E8%A8%88%E7%89%B9%E5%88%A5%E5%BD%A2%E7%8B%80%E7%9A%84%E5%9C%96%E7%89%87-%E6%AF%94%E6%96%B9%E6%96%9C%E9%82%8A-%E6%84%9B%E5%BF%83-92f63ae10d4a?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/92f63ae10d4a</guid>
            <category><![CDATA[uibezierpath]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 10:38:42 GMT</pubDate>
            <atom:updated>2021-01-21T10:38:42.272Z</atom:updated>
            <content:encoded><![CDATA[<h3>學習記錄#利用 UIBezierPath 設計特別形狀的圖片 — 比方斜邊 &amp; 愛心</h3><p>目的:利用UIBezierPath創作任意形狀的圖片。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*v28RlUX-yi2MSTSPf6HWsA.png" /></figure><blockquote><strong>1.畫面加入imageView</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNrVf1yxFwps8VM29gOcXw.png" /></figure><blockquote>2.<strong>新增繼承 UIImageView 的 SharpImageView。</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u8WN8R0TXxKfBbLDAtHOAg.png" /></figure><blockquote><strong>3.選擇 iOS 下的 Cocoa Touch Class。</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqymK2HRIYmJu3sTv2xexA.png" /></figure><blockquote><strong>4.記得 Subclass of (父類別) 要設為 UIImageView。</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPbMzQ7IH9jq3mTQhco0ng.png" /></figure><p>5.<strong><em>將 image view 的 Class(類別)設為 SharpImageView。</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0lnECIQgtW1-vLHA9bUnw.png" /></figure><p>6.<strong><em>在 SharpImageView.swift 裡加入製造斜邊的程式碼。</em></strong></p><p>定義 function layoutSubviews。</p><pre><strong>override</strong> <strong>func</strong> layoutSubviews() {</pre><pre><strong>super</strong>.layoutSubviews()</pre><pre>//宣告path為貝茲曲線物件<br><strong>let</strong> path = UIBezierPath()</pre><pre>//第一個座標點，使用CGPoint.zero(x=0,y=0)<br>path.move(to: CGPoint.zero)</pre><pre>//使用bouns取得圖片寬度，畫到圖像右上邊界(x為圖片寬度,y不變)<br>path.addLine(to: CGPoint(x: bounds.width, y: 0))</pre><pre>//使用bouns取得圖片寬度，畫到圖像右下邊界(x不變，y畫到圖片右下邊界)<br>path.addLine(to: CGPoint(x: bounds.width, y: bounds.height))</pre><pre>//使用bouns取得圖片寬度，畫到圖像左下邊界(x到圖片左邊，y畫到圖片左下高度*0.8)也就是往上裁切<br>path.addLine(to: CGPoint(x: 0, y: bounds.height * 0.8))</pre><pre>path.close()</pre><pre><strong>let</strong> shapeLayer = CAShapeLayer()</pre><pre>shapeLayer.path = path.cgPath</pre><pre>layer.mask = shapeLayer</pre><pre>}</pre><p>在二~四張一開始就要畫下來所以改成</p><pre>path.addLine(to: CGPoint(x: bounds.width, y: bounds.height * 0.2))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*v28RlUX-yi2MSTSPf6HWsA.png" /></figure><p>7.<strong><em>在 SharpImageView.swift 裡加入製造星星的程式碼。</em></strong></p><pre><strong>override</strong> <strong>func</strong> layoutSubviews() {</pre><pre><strong>super</strong>.layoutSubviews()</pre><pre><strong>let</strong> path = UIBezierPath()</pre><pre>path.move(to: CGPoint(x: 91, y: 14))</pre><pre>path.addLine(to: CGPoint(x: 112, y: 60))</pre><pre>path.addLine(to: CGPoint(x: 161, y: 69))</pre><pre>path.addLine(to: CGPoint(x: 129, y: 109))</pre><pre>path.addLine(to: CGPoint(x: 135, y: 163))</pre><pre>path.addLine(to: CGPoint(x: 91, y: 141))</pre><pre>path.addLine(to: CGPoint(x: 45, y: 163))</pre><pre>path.addLine(to: CGPoint(x: 51, y: 110))</pre><pre>path.addLine(to: CGPoint(x: 14, y: 72))</pre><pre>path.addLine(to: CGPoint(x: 64, y: 60))</pre><pre>path.close()</pre><pre><strong>let</strong> shapeLayer = CAShapeLayer()</pre><pre>shapeLayer.path = path.cgPath</pre><pre>layer.mask = shapeLayer</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*34ICZiac5RtClvn1IrAeCA.png" /></figure><p>8.<strong><em>在 SharpImageView.swift 裡加入製造愛心的程式碼。</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*nQnRS8rz1iknsq3eI72nJQ.png" /></figure><pre><strong>override</strong> <strong>func</strong> layoutSubviews() {</pre><pre><strong>super</strong>.layoutSubviews()</pre><pre><strong>let</strong> path = UIBezierPath()</pre><pre>path.move(to: CGPoint(x: 160,y: 120))</pre><pre>path.addQuadCurve(to: CGPoint(x: 160, y: 260), controlPoint: CGPoint(x: 280, y: 60))</pre><pre>path.addQuadCurve(to: CGPoint(x: 160, y: 120), controlPoint: CGPoint(x: 50, y: 60))</pre><pre>path.close()</pre><pre><strong>let</strong> shapeLayer = CAShapeLayer()</pre><pre>shapeLayer.path = path.cgPath</pre><pre>layer.mask = shapeLayer}</pre><p>參考資料:</p><ul><li><a href="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/%E5%88%A9%E7%94%A8-uibezierpath-%E8%A8%AD%E8%A8%88%E7%89%B9%E5%88%A5%E5%BD%A2%E7%8B%80%E7%9A%84%E5%9C%96%E7%89%87-%E6%AF%94%E6%96%B9%E6%96%9C%E9%82%8A-%E6%84%9B%E5%BF%83-9741747f0063">利用 UIBezierPath 設計特別形狀的圖片 — 比方斜邊 &amp; 愛心</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E5%88%A9%E7%94%A8-uibezierpath-%E8%A8%AD%E8%A8%88%E7%89%B9%E5%88%A5%E5%BD%A2%E7%8B%80%E7%9A%84%E5%9C%96%E7%89%87-3ed452f88b6d">利用 UIBezierPath 設計特別形狀的圖片</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E5%88%A9%E7%94%A8-uibezierpath-%E8%A8%AD%E8%A8%88%E7%89%B9%E5%88%A5%E5%BD%A2%E7%8B%80%E7%9A%84%E5%9C%96%E7%89%87-%E9%A2%A8%E6%99%AF%E4%BB%8B%E7%B4%B9-8247277ec9a6">利用 UIBezierPath 設計特別形狀的圖片 — 風景介紹</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92f63ae10d4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-%E5%88%A9%E7%94%A8-uibezierpath-%E8%A8%AD%E8%A8%88%E7%89%B9%E5%88%A5%E5%BD%A2%E7%8B%80%E7%9A%84%E5%9C%96%E7%89%87-%E6%AF%94%E6%96%B9%E6%96%9C%E9%82%8A-%E6%84%9B%E5%BF%83-92f63ae10d4a">學習記錄#利用 UIBezierPath 設計特別形狀的圖片 — 比方斜邊 &amp; 愛心</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#34 數學小神童]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-34-%E6%95%B8%E5%AD%B8%E5%B0%8F%E7%A5%9E%E7%AB%A5-ae57187115a8?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae57187115a8</guid>
            <category><![CDATA[calculator]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 14:04:35 GMT</pubDate>
            <atom:updated>2021-01-17T14:04:35.776Z</atom:updated>
            <content:encoded><![CDATA[<p>目的: 學習 IBOutlet 和 IBAction。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*d5qloEazXPyJH1-8O7PAig.png" /></figure><p>1.利用 UISegmentedControl 元件切換加減乘除時，將兩個 text field 的數字相加，相減，相乘或相除的結果顯示在畫面上。</p><pre><strong>func</strong> update(){</pre><pre><strong>let</strong> num1 = Int(numberTextField.text!) ?? 0</pre><pre><strong>let</strong> num2 = Int(number2TextField.text!) ?? 0<br></pre><pre><strong>switch</strong> calculate {</pre><pre><strong>case</strong> 0:</pre><pre>resultLabel.text = &quot;\(num1 + num2)&quot;</pre><pre><strong>case</strong> 1:</pre><pre>resultLabel.text = &quot;\(num1 - num2)&quot;</pre><pre><strong>case</strong> 2:</pre><pre>resultLabel.text = &quot;\(num1 * num2)&quot;</pre><pre><strong>case</strong> 3:</pre><pre>resultLabel.text = &quot;\(num1 / num2)&quot;</pre><pre><strong>default</strong>:</pre><pre><strong>break</strong></pre><pre>  }</pre><pre>}</pre><p>2.在 text field 修改數字時，答案即時改變。</p><pre><strong>@IBAction</strong> <strong>func</strong> update(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>update()</pre><pre>}<br><strong>@IBAction</strong> <strong>func</strong> update2(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>update()</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dabg6OcDOoVz_rMtmc1crA.png" /><figcaption>每次改變輸入的數字，會直接更新答案</figcaption></figure><p>3.收鍵盤。</p><pre><strong>func</strong> addTapGesture(){</pre><pre><strong>let</strong> tap = UITapGestureRecognizer(target: <strong>self</strong>,action: <strong>#selector</strong>(hideKeyboard))</pre><pre>view.addGestureRecognizer(tap)</pre><pre>}</pre><pre><strong>@objc</strong> <strong>private</strong> <strong>func</strong> hideKeyboard(){</pre><pre><strong>self</strong>.view.endEditing(<strong>true</strong>)</pre><pre>}</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre>addTapGesture()</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>}</pre><p>意外發現，有時點選模擬器竟然無法開啟數字鍵.............</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wbik6WH6aZAoEi9dF7RQFA.png" /></figure><p>原來有人跟我遇到一樣的方式，並提供解決方式太棒了。</p><p><a href="https://developer.apple.com/forums/thread/126616">&quot;Can&#39;t find keyplane that supports... | Apple Developer Forums</a></p><h3>成果</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*lPfhC_cwJFBYUzXGGhZ_Kw.gif" /></figure><p>完整程式Github</p><p><a href="https://github.com/Chingwenluo/calculate">Chingwenluo/calculate</a></p><p>參考資料:</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/34-%E6%95%B8%E5%AD%B8%E5%B0%8F%E7%A5%9E%E7%AB%A5-ff016d513295">#34 數學小神童</a></li><li><a href="https://medium.com/@heggyy/ios-tip-calculator-ce1633b7f5da">iOS app: tip 💁🏻‍ calculator</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae57187115a8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-34-%E6%95%B8%E5%AD%B8%E5%B0%8F%E7%A5%9E%E7%AB%A5-ae57187115a8">學習記錄#34 數學小神童</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#8 甜蜜的 Apple Pie]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-8-%E7%94%9C%E8%9C%9C%E7%9A%84-apple-pie-21f710870ccd?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/21f710870ccd</guid>
            <category><![CDATA[apple-pie]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 06:25:10 GMT</pubDate>
            <atom:updated>2021-01-11T06:25:10.449Z</atom:updated>
            <content:encoded><![CDATA[<p>目的: <br>研讀 Apple 官方電子書 App Development with Swift 第二章，完成它的 Guided Project，Apple Pie，學習 array，struct 自訂型別，didSet，for in，string interpolation。</p><p>題目參考來源:<br>Apple 官方電子書 App Development with Swift 裡 ch2 的 Guided Project，Apple Pie。</p><p><a href="https://books.apple.com/tw/book/app-development-with-swift/id1219117996">‎App Development with Swift</a></p><h3>Apple 官方簡單版</h3><p>規則如下:</p><p>1.畫面下方以 _ 顯示要猜的單字，比方單字是 peter，一開始將顯示<br>_ _ _ _ _，五個底線。</p><p>2.如果猜的字母在單字裡，原本顯示的 _ 將變成猜的字母，比方單字是 peter，當我們猜了 p 跟 e，畫面下方將顯示 p e _ e _。</p><pre><strong>var</strong> formattedWord: String  {</pre><pre><strong>var</strong> guessedWord = &quot;&quot;</pre><pre><strong>      for</strong> letter <strong>in</strong> word{</pre><pre><strong>          if</strong> guessedLetters.contains(letter)  {</pre><pre>                  guessedWord += &quot;\(letter)&quot;<br>              }</pre><pre><strong>           else</strong> {<br>                  guessedWord += &quot;_&quot;<br>              }<br>      }</pre><pre><strong>         return</strong> guessedWord<br> }</pre><p>3.如果猜的字母沒有在單字裡，將會掉一顆蘋果，如果七顆蘋果掉光光的話，你就輸了。</p><pre><strong> let</strong> incorrectMovesAllowed = 7</pre><pre><strong>mutating</strong> <strong>func</strong> playerGuessed (letter: Character) {</pre><pre>      guessedLetters.append(letter)</pre><pre><strong>           if</strong> !word.contains(letter){</pre><pre>                  incorrectMovesRemaining -= 1</pre><pre>              }<br>  }</pre><p>4.猜過的字母不能再按。</p><pre>sender.isEnabled = <strong>false</strong></pre><p>5.有多個單字可猜，最下方將顯示單字猜對的次數，比方猜對 3 次，猜錯 1 次。</p><p>6.猜完一個單字後，更新最下方的猜對次數，繼續猜下一個單字，此時蘋果會回到七個，全部字母也會重新變成可以按。</p><pre><strong>var</strong> totalWins = 0  {</pre><pre><strong>      didSet</strong> {</pre><pre>        newRound()<br>     }<br>}</pre><pre><strong>var</strong> totalLosses = 0  {</pre><pre><strong>      didSet</strong> {</pre><pre>        newRound()<br>     }<br>}<br></pre><pre><strong>func</strong> updateUI() {</pre><pre><strong>   var</strong> letters = [String]()</pre><pre><strong>      for</strong> letter <strong>in</strong> currentGame.formattedWord {</pre><pre>              letters.append(String(letter))<br>          }</pre><pre><strong>    let</strong> wordWithSpacing = letters.joined (separator:&quot; &quot;)</pre><pre>          correctWordLabel.text = wordWithSpacing</pre><pre>          scoreLabel.text = &quot;猜對: \(totalWins),猜錯: \(totalLosses)&quot;</pre><pre>          treeImageView.image = UIImage(named: &quot;Tree \   (currentGame.incorrectMovesRemaining)&quot;)</pre><pre>}</pre><pre>//按鈕重新可點選<strong><br>func</strong> enableLetterButtons(_enable: Bool)  {</pre><pre><strong>      for</strong> button <strong>in</strong> letterButtons  {</pre><pre>           button.isEnabled = _enable<strong><br></strong>      }<br>}</pre><pre><strong>func</strong> newRound() {</pre><pre><strong>   if</strong>  listOfWords.isEmpty == <strong>false</strong> {</pre><pre><strong>   let</strong> newWord = listOfWords.removeFirst()</pre><pre>       currentGame = Game(word: newWord, incorrectMovesRemaining:      incorrectMovesAllowed, guessedLetters: [])</pre><pre>        enableLetterButtons(_enable: <strong>true</strong>)</pre><pre>        updateUI()</pre><pre>       }</pre><pre><strong>       else</strong> {</pre><pre>         enableLetterButtons(_enable: <strong>false</strong>)</pre><pre>   }</pre><pre>}</pre><pre><strong>func</strong> updateUI() {</pre><pre><strong>  var</strong> letters = [String]()</pre><pre><strong>    for</strong> letter <strong>in</strong> currentGame.formattedWord {</pre><pre>         letters.append(String(letter))<br>      }</pre><pre><strong>  let</strong> wordWithSpacing = letters.joined (separator:&quot; &quot;)</pre><pre>         correctWordLabel.text = wordWithSpacing</pre><pre>         scoreLabel.text = &quot;猜對: \(totalWins),猜錯: \(totalLosses)&quot;</pre><pre>        treeImageView.image = UIImage(named: &quot;Tree \  (currentGame.incorrectMovesRemaining)&quot;)</pre><pre>}<br></pre><pre><strong>func</strong> updateGameState() {</pre><pre><strong>if</strong> currentGame.incorrectMovesRemaining == 0 {</pre><pre>       totalLosses += 1<br>  }</pre><pre><strong>  else</strong> <strong>if</strong> currentGame.word == currentGame.formattedWord {</pre><pre>       totalWins += 1<br>  }</pre><pre><strong>  else</strong> {</pre><pre>    updateUI ()<br>  }</pre><pre>}</pre><p>初步成果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*4aOcf3gQ_RbxNzPqAw3fUQ.gif" /></figure><h3>擴充版</h3><ol><li>加上計分機制，猜對完整的單字有分數。</li></ol><pre>guessRight += 10</pre><p>2.加上音效，掉蘋果時有音效。</p><pre><strong>func</strong> speek(){</pre><pre><strong>let</strong> speechUtterance = AVSpeechUtterance(string: &quot;oh oh 猜錯了&quot;)</pre><pre>speechUtterance.voice = AVSpeechSynthesisVoice(language: &quot;zh-TW&quot;)</pre><pre>speechUtterance.rate = 0.5</pre><pre>speechUtterance.postUtteranceDelay = 50</pre><pre><strong>let</strong> synthesizer = AVSpeechSynthesizer()</pre><pre>synthesizer.speak(speechUtterance)</pre><pre>}</pre><p>3.計時制，目標在愈短的時間內猜對5個單字。</p><pre><strong>var</strong> gameTimer:Timer?</pre><pre><strong>var</strong> timerCount = 0<br></pre><pre><strong>@objc</strong> <strong>func</strong> timerSet() {</pre><pre>timerCount += 1</pre><pre><strong>let</strong> mins =  timerCount/60</pre><pre><strong>let</strong> seconds = timerCount % 60</pre><pre><strong>self</strong>.timeLabel.text = &quot; 時間 \(String(format:&quot;%.2d&quot;, mins)):\(String(format:&quot;%.2d&quot;, seconds))&quot;</pre><pre>totalTime += 1</pre><pre>}</pre><pre>//全數猜中立即停止<strong><br>if</strong> totalWins == 5{</pre><pre>//時間停止<br>gameTimer?.invalidate()</pre><pre><strong>let</strong> alert = UIAlertController(title: &quot;花費時間&quot;, message: &quot;\(totalTime)秒&quot;  , preferredStyle: .alert)</pre><pre><strong>let</strong> action = UIAlertAction(title: &quot;結束&quot;, style: .default) { (<strong>_</strong>) <strong>in</strong></pre><pre>}</pre><pre>alert.addAction(action)</pre><pre>present(alert, animated: <strong>true</strong>, completion: <strong>nil</strong>)</pre><pre>}</pre><p>4.使用者可選擇不同的水果。</p><pre><strong>switch</strong> select {</pre><pre><strong>case</strong> 0:</pre><pre>treeImageView.image = UIImage(named: &quot;Tree \(currentGame.incorrectMovesRemainingPlayer1)&quot;)</pre><pre><strong>case</strong> 1:</pre><pre>treeImageView.image = UIImage(named: &quot;orange \(currentGame.incorrectMovesRemainingPlayer1)&quot;)</pre><pre><strong>case</strong> 2:</pre><pre>treeImageView.image = UIImage(named: &quot;Strawberry \(currentGame.incorrectMovesRemainingPlayer1)&quot;)</pre><pre><strong>default</strong>:</pre><pre><strong>break</strong></pre><pre>}</pre><p>成果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*-0c8RT13TI4WVyJttPYRKw.gif" /></figure><p>有聲版成果</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FU2FBVOT7Iv4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DU2FBVOT7Iv4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FU2FBVOT7Iv4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fcd8a62e3e62aecadcb75750493dc48/href">https://medium.com/media/4fcd8a62e3e62aecadcb75750493dc48/href</a></iframe><p>完整程式Github</p><p><a href="https://github.com/Chingwenluo/applePie">Chingwenluo/applePie</a></p><p>參考資料</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/8-apple-pie-59763149efb0">#8 甜蜜的 Apple Pie (恐怖的 Hangman)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21f710870ccd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-8-%E7%94%9C%E8%9C%9C%E7%9A%84-apple-pie-21f710870ccd">學習記錄#8 甜蜜的 Apple Pie</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#120 App 的解鎖畫面(passcode)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-120-app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-4ec95f79510c?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ec95f79510c</guid>
            <category><![CDATA[passcode]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Mon, 04 Jan 2021 10:55:19 GMT</pubDate>
            <atom:updated>2021-01-05T13:49:57.157Z</atom:updated>
            <content:encoded><![CDATA[<p>還記得小時候第一部卡通獅子王，看完一整個令人驚艷無法忘懷......</p><p>這次解鎖畫面主題就決定是獅子王。</p><p>範例: LINE 的解鎖畫面。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*GdYnc7y30kpY-gWFI8Uj0A.png" /></figure><p>1.設定密碼圖示</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passImageView2: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passImageView1: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passImageView3: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passImageView4: UIImageView!</pre><p>2.密碼輸入後的判讀</p><pre><strong>func</strong> checkPassCode(){</pre><pre><strong>if</strong> correctPassCode == guessPasscode {</pre><pre>performSegue(withIdentifier: &quot;correctPassCode&quot;, sender: <strong>self</strong>)</pre><pre>} <strong>else</strong> {</pre><pre>guessPasscode = []</pre><pre>passImageView1.isHidden = <strong>true</strong></pre><pre>passImageView2.isHidden = <strong>true</strong></pre><pre>passImageView3.isHidden = <strong>true</strong></pre><pre>passImageView4.isHidden = <strong>true</strong></pre><pre><strong>let</strong> alert = UIAlertController(title: &quot;密碼錯誤&quot;, message: &quot;輸入的密碼不正確!&quot;, preferredStyle: .alert)</pre><pre><strong>let</strong> action = UIAlertAction(title: &quot;請重新輸入&quot;, style: .default) { (<strong>_</strong>) <strong>in</strong></pre><pre>}</pre><pre>alert.addAction(action)</pre><pre>present(alert, animated: <strong>true</strong>, completion: <strong>nil</strong>)</pre><pre>  }</pre><pre>}</pre><p>3.密碼輸入時的圖片顯示</p><pre><strong>func</strong> passcodeImage(){</pre><pre><strong>if</strong>  guessPasscode.count == 0 {</pre><pre>passImageView1.isHidden = <strong>true</strong></pre><pre>passImageView2.isHidden = <strong>true</strong></pre><pre>passImageView3.isHidden = <strong>true</strong></pre><pre>passImageView4.isHidden = <strong>true</strong></pre><pre>} <strong>else</strong> <strong>if</strong> guessPasscode.count == 1 {</pre><pre>passImageView1.isHidden = <strong>false</strong></pre><pre>passImageView2.isHidden = <strong>true</strong></pre><pre>passImageView3.isHidden = <strong>true</strong></pre><pre>passImageView4.isHidden = <strong>true</strong></pre><pre>} <strong>else</strong> <strong>if</strong> guessPasscode.count == 2 {</pre><pre>passImageView1.isHidden = <strong>false</strong></pre><pre>passImageView2.isHidden = <strong>false</strong></pre><pre>passImageView3.isHidden = <strong>true</strong></pre><pre>passImageView4.isHidden = <strong>true</strong></pre><pre>} <strong>else</strong> <strong>if</strong> guessPasscode.count == 3 {</pre><pre>passImageView1.isHidden = <strong>false</strong></pre><pre>passImageView2.isHidden = <strong>false</strong></pre><pre>passImageView3.isHidden = <strong>false</strong></pre><pre>passImageView4.isHidden = <strong>true</strong></pre><pre>} <strong>else</strong> <strong>if</strong> guessPasscode.count == 4 {</pre><pre>passImageView1.isHidden = <strong>false</strong></pre><pre>passImageView2.isHidden = <strong>false</strong></pre><pre>passImageView3.isHidden = <strong>false</strong></pre><pre>passImageView4.isHidden = <strong>false</strong></pre><pre>checkPassCode()</pre><pre>}</pre><pre>}</pre><p>4.輸入密碼</p><pre><strong>@IBAction</strong> <strong>func</strong> numberBtn(<strong>_</strong> sender: UIButton) {</pre><pre><strong>let</strong> button = sender.tag</pre><pre>guessPasscode.append(button)</pre><pre>passcodeImage()</pre><pre>}</pre><p>5.刪除密碼</p><pre><strong>@IBAction</strong> <strong>func</strong> deleteBtn(<strong>_</strong> sender: UIButton) {</pre><pre><strong>if</strong> 0...3 ~= guessPasscode.count {</pre><pre>guessPasscode.removeLast()</pre><pre>passcodeImage()</pre><pre>    }</pre><pre>}</pre><h3><strong>成果</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*6f-ghxn345Wp7LD0bVyI6w.gif" /></figure><p>完整程式Github</p><p><a href="https://github.com/Chingwenluo/passcode">Chingwenluo/passcode</a></p><p>參考資料:</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/120-app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-552e9b90c97c">#120 App 的解鎖畫面(passcode)</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/120-app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-d91746609d29">#120 App 的解鎖畫面(passcode)</a></li></ul><p>最後來個獅子王經典-主題曲「生生不息Circle Of Life」</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV8fMbPkFyak%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV8fMbPkFyak&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV8fMbPkFyak%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb999b7d4c61cbd015ddeef24c809acb/href">https://medium.com/media/fb999b7d4c61cbd015ddeef24c809acb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ec95f79510c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-120-app-%E7%9A%84%E8%A7%A3%E9%8E%96%E7%95%AB%E9%9D%A2-passcode-4ec95f79510c">學習記錄#120 App 的解鎖畫面(passcode)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#58 Swift 的九九乘法]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-58-swift-%E7%9A%84%E4%B9%9D%E4%B9%9D%E4%B9%98%E6%B3%95-c3bd8437ca22?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3bd8437ca22</guid>
            <category><![CDATA[九九乘法表]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 14:29:41 GMT</pubDate>
            <atom:updated>2020-12-12T14:29:41.623Z</atom:updated>
            <content:encoded><![CDATA[<p>目的: 學習 for 迴圈</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Vq349YN_3ucCOrSt0C2RkA.png" /></figure><blockquote><strong><em>1. 在 playground 用 print 印出結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*pcIW_weddAb_idHoPLtNFw.png" /></figure><pre><strong>for</strong> i <strong>in</strong> 1...9 {</pre><pre><strong>   for</strong> j <strong>in</strong> 1...9 {</pre><pre><strong>     let</strong> sum = i * j</pre><pre>     print(&quot;\(i)*\(j)=\(sum)&quot;)</pre><pre>    }</pre><pre>}</pre><blockquote><strong><em>2. 製作九九乘法表畫面</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*FjAo7MQ2p2mNECpKyZvB3Q.png" /></figure><pre><strong>let</strong> width = view.frame.width / 10</pre><pre><strong>var</strong> x: CGFloat = 20</pre><pre><strong>for</strong> Horizontal <strong>in</strong> 1...9 {</pre><pre><strong>var</strong> y: CGFloat = 20</pre><pre><strong>for</strong> straight <strong>in</strong> 1...9 {</pre><pre>//產生多個label</pre><pre><strong>let</strong> label = UILabel(frame: CGRect(x: x, y: y, width: 30 , height: 30))</pre><pre><strong>if</strong>  Horizontal != 0, straight == 0 {</pre><pre>label.text = &quot;\(Horizontal)&quot;</pre><pre>}<strong>else</strong> <strong>if</strong> Horizontal == 0, straight != 0 {</pre><pre>label.text = &quot;\(straight)&quot;</pre><pre>}<strong>else</strong>{</pre><pre>label.text = &quot;\(straight*Horizontal)&quot;</pre><pre>}</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>view.addSubview(label)</pre><pre>y = y + width</pre><pre>}</pre><pre>x = x + width</pre><pre>}</pre><blockquote><strong><em>3.某些 label 顯示特別的顏色 。第一排和第一列的 label 文字粗體。</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*WpGrfRFV1vxlF24VfeMEXA.png" /></figure><pre>//title設粗體</pre><pre><strong>self</strong>.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 20)]</pre><pre><strong>let</strong> width = view.frame.width / 10</pre><pre><strong>var</strong> x: CGFloat = 5</pre><pre><strong>for</strong> Horizontal <strong>in</strong> 0...9 {</pre><pre><strong>var</strong> y: CGFloat = 90</pre><pre><strong>for</strong> straight <strong>in</strong> 0...9 {</pre><pre>//產生多個label</pre><pre><strong>let</strong> label = UILabel(frame: CGRect(x: x, y: y, width: 30 , height: 30))</pre><pre><strong>if</strong> Horizontal == 0 , straight == 0 {</pre><pre>label.text = &quot;X&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong> <strong>if</strong>  Horizontal != 0, straight == 0 {</pre><pre>label.text = &quot;\(Horizontal)&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong> <strong>if</strong> Horizontal == 0, straight != 0 {</pre><pre>label.text = &quot;\(straight)&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong>{</pre><pre>label.text = &quot;\(straight*Horizontal)&quot;</pre><pre>label.font = UIFont.systemFont(ofSize: 17)</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}</pre><pre><strong>if</strong>  (Horizontal &gt; 1 &amp;&amp; Horizontal &lt; 5 &amp;&amp; Horizontal+straight == 10) || (Horizontal &gt;= 5 &amp;&amp; Horizontal == straight &amp;&amp; Horizontal != 9)  {</pre><pre>label.backgroundColor = UIColor.systemPink</pre><pre>} <strong>else</strong> <strong>if</strong> straight == 9 ,Horizontal % 2 != 0 {</pre><pre>label.backgroundColor = UIColor.orange</pre><pre>} <strong>else</strong> <strong>if</strong> straight == 9 , Horizontal != 0 , Horizontal % 2 != 1{</pre><pre>label.backgroundColor = UIColor.systemBlue</pre><pre>}</pre><pre>view.addSubview(label)</pre><pre>y = y + width</pre><pre>}</pre><pre>x = x + width</pre><pre>}</pre><blockquote><strong><em>4.加上 slider 控制數量</em></strong></blockquote><pre>sender.value = sender.value.rounded()</pre><pre><strong>let</strong> number = Int(sender.value)</pre><pre>shownumber.text = &quot;\(number)乘\(number)&quot;</pre><pre><strong>let</strong> width = view.frame.width / 10</pre><pre><strong>var</strong> x: CGFloat = 5</pre><pre><strong>for</strong> Horizontal <strong>in</strong> 0...number {</pre><pre><strong>var</strong> y: CGFloat = 90</pre><pre><strong>for</strong> straight <strong>in</strong> 0...number {</pre><pre>//產生多個label</pre><pre><strong>let</strong> label = UILabel(frame: CGRect(x: x, y: y, width: 30 , height: 30))</pre><pre><strong>if</strong> Horizontal == 0 , straight == 0 {</pre><pre>label.text = &quot;X&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong> <strong>if</strong>  Horizontal != 0, straight == 0 {</pre><pre>label.text = &quot;\(Horizontal)&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong> <strong>if</strong> Horizontal == 0, straight != 0 {</pre><pre>label.text = &quot;\(straight)&quot;</pre><pre>label.font = UIFont.boldSystemFont(ofSize: 17) //文字粗體</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}<strong>else</strong>{</pre><pre>label.text = &quot;\(straight*Horizontal)&quot;</pre><pre>label.font = UIFont.systemFont(ofSize: 17)</pre><pre>label.textAlignment = .center //文字置中</pre><pre>}</pre><pre><strong>if</strong>  (Horizontal &gt; 1 &amp;&amp; Horizontal &lt; 5 &amp;&amp; Horizontal+straight == 10) || (Horizontal &gt;= 5 &amp;&amp; Horizontal == straight &amp;&amp; Horizontal != 9)  {</pre><pre>label.backgroundColor = UIColor.systemPink</pre><pre>} <strong>else</strong> <strong>if</strong> straight == 9 ,Horizontal % 2 != 0 {</pre><pre>label.backgroundColor = UIColor.orange</pre><pre>} <strong>else</strong> <strong>if</strong> straight == 9 , Horizontal != 0 , Horizontal % 2 != 1{</pre><pre>label.backgroundColor = UIColor.systemBlue</pre><pre>}</pre><pre>view.addSubview(label)</pre><pre>y = y + width</pre><pre>}</pre><pre>x = x + width</pre><pre>}</pre><p>成果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*Rsxi-MCJs4J2zx53X5EdFA.gif" /></figure><p>完整程式Github</p><p><a href="https://github.com/Chingwenluo/9-9">Chingwenluo/9-9</a></p><p>參考資料:</p><ul><li><a href="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/%E5%AF%A6%E7%8F%BE%E9%80%8F%E6%98%8E%E7%9A%84-navigation-bar-%E5%88%A9%E7%94%A8%E5%AE%83%E7%9A%84%E8%83%8C%E6%99%AF%E5%9C%96%E5%92%8C%E9%99%B0%E5%BD%B1%E5%9C%96-c9ba9e81f122">實現透明的 navigation bar &amp; tab bar — 利用它的背景圖和陰影圖</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/swift-%E4%B9%9D%E4%B9%9D%E4%B9%98%E6%B3%95app-multiplication-table-app-efe817260f62">Swift 九九乘法App/Multiplication Table App</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/swift-%E5%AF%AB%E4%B9%9D%E4%B9%9D%E4%B9%98%E6%B3%95%E8%A1%A8-bb81d29cab04">Swift 寫九九乘法表</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/58-swift-%E7%9A%84%E4%B9%9D%E4%B9%9D%E4%B9%98%E6%B3%95-app-53097ba20b81">#58 Swift 的九九乘法 App</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3bd8437ca22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-58-swift-%E7%9A%84%E4%B9%9D%E4%B9%9D%E4%B9%98%E6%B3%95-c3bd8437ca22">學習記錄#58 Swift 的九九乘法</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[學習記錄#60 畫星星蘋果 — nested loop(巢狀迴圈)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-60-%E7%95%AB%E6%98%9F%E6%98%9F%E8%98%8B%E6%9E%9C-nested-loop-%E5%B7%A2%E7%8B%80%E8%BF%B4%E5%9C%88-c6beadc6b492?source=rss-e6a184b99840------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6beadc6b492</guid>
            <category><![CDATA[nested-loop]]></category>
            <dc:creator><![CDATA[ChingWen]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 14:28:52 GMT</pubDate>
            <atom:updated>2020-12-12T14:28:52.003Z</atom:updated>
            <content:encoded><![CDATA[<h3>學習記錄#60 畫星星蘋果 — nested loop(巢狀迴圈)</h3><p>目的: 學習使用 for 迴圈。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*wueM09Yz9aWeC4HYrfckNA.png" /></figure><ol><li>從 segmented control 選擇形狀，有正方形，三角形，金字塔和菱形四種。</li><li>從 slider 改變數量。</li><li>畫 2 種 Apple，比方有紅色跟綠色。</li></ol><blockquote>正方形</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*gdKWpu7znqA7udCoWoeZUA.gif" /></figure><pre>//正方形</pre><pre><strong>for</strong> <strong>_</strong> <strong>in</strong> 1...number {</pre><pre><strong>let</strong> star = number</pre><pre><strong>let</strong> showstar = String(repeating: &quot;⭐️&quot;, count: star)</pre><pre>showlabel = showlabel + showstar</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>   }</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><p>另一種寫法</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*gdKWpu7znqA7udCoWoeZUA.gif" /></figure><pre>//正方形</pre><pre><strong>for</strong> <strong>_</strong> <strong>in</strong> 1...number {</pre><pre><strong>       for</strong> <strong>_</strong> <strong>in</strong> 1...number {</pre><pre>          showlabel = showlabel + &quot;⭐️&quot;</pre><pre>     }</pre><pre>          showlabel = showlabel + &quot;\n&quot;</pre><pre>}</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>三角形</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*OO9ZcMafYuTfdgcNw7a7iQ.gif" /></figure><pre>///三角形</pre><pre><strong>for</strong> i <strong>in</strong> 1...number  {</pre><pre><strong>   for</strong> <strong>_</strong> <strong>in</strong> 1...i {</pre><pre>showlabel = showlabel + &quot;⭐️&quot;</pre><pre>   }</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre> }</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>金字塔</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*kA-o4JeqfOApcBVRUqy7eQ.gif" /></figure><pre>//金字塔</pre><pre><strong>for</strong> i <strong>in</strong> 1...number {</pre><pre><strong>let</strong> apple = number - i</pre><pre><strong>let</strong> star = (i*2) - 1</pre><pre><strong>let</strong> showapple = String(repeating: &quot;🍎&quot;, count: apple)</pre><pre><strong>let</strong> showstar = String(repeating: &quot;⭐️&quot;, count:     star)</pre><pre>showlabel = showlabel + showapple + showstar</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><pre>}</pre><blockquote>菱形</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*AfHzfebcziLUdrrnkjdgtQ.gif" /></figure><pre>//菱形</pre><pre><strong>var</strong> apple:Int</pre><pre><strong>var</strong> star:Int</pre><pre><strong>for</strong> i <strong>in</strong> 1...number*2 - 1 {</pre><pre><strong>   if</strong> i &lt; number {</pre><pre>     star =  (i*2) - 1</pre><pre>     apple = number - i</pre><pre>    } <strong>else</strong> {</pre><pre>     star =  (number * 2 - i ) * 2 - 1</pre><pre>     apple =  i - number</pre><pre>  }</pre><pre><strong>let</strong> showstar = String(repeating: &quot;⭐️&quot;, count: star)</pre><pre><strong>let</strong> showapple = String(repeating: &quot;🍎&quot;, count: apple )</pre><pre>showlabel = showlabel + showapple + showstar</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>倒三角</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*g8PtPLcfKU_hX7CxWGlzlw.gif" /></figure><pre>//倒三角</pre><pre><strong>for</strong> i <strong>in</strong> 1...number  {</pre><pre><strong>let</strong> star = number - i + 1</pre><pre><strong>let</strong> showstar = String(repeating: &quot;⭐️&quot;, count: star)</pre><pre>showlabel = showlabel + showstar</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>}</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>正方形--將最後一行變成蘋果</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*AJKmeTDixG39zKK_EMXNAA.gif" /></figure><pre>//正方形劃底線</pre><pre><strong>for</strong> i <strong>in</strong> 1...number {</pre><pre><strong>  for</strong> <strong>_</strong> <strong>in</strong> 1...number {</pre><pre><strong>     if</strong> i == number {</pre><pre>showlabel = showlabel + &quot;🍎&quot;</pre><pre>                } <strong>else</strong> {</pre><pre>showlabel = showlabel + &quot;⭐️&quot;</pre><pre>                  }</pre><pre>     }</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>  }</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>正方形 — 將斜線變成蘋果</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*YssqkXj2BBXbk7niyP1njg.gif" /></figure><pre>//正方形劃斜線</pre><pre><strong>for</strong> i <strong>in</strong> 1...number {</pre><pre><strong> for</strong> j <strong>in</strong> 1...number {</pre><pre><strong>  if</strong> i + j == number + 1 {</pre><pre>showlabel = showlabel + &quot;🍎&quot;</pre><pre>  } <strong>else</strong> {</pre><pre>showlabel = showlabel + &quot;⭐️&quot;</pre><pre>    }</pre><pre> }</pre><pre>showlabel = showlabel + &quot;\n&quot;</pre><pre>}</pre><pre>label.text = showlabel</pre><pre>showslider.text = &quot;\(number)&quot;</pre><blockquote>正方形 — 星星與蘋果交錯</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*pLyWuyKr3VkHOQAJNG4mwQ.gif" /></figure><pre>//正方形圖案交錯</pre><pre><strong>for</strong> i <strong>in</strong> 1...number {</pre><pre><strong>   for</strong> j <strong>in</strong> 1...number {</pre><pre><strong>       if</strong> i % 2 == 0 , j % 2 != 0 {</pre><pre>            showlabel = showlabel + &quot;🍎&quot;</pre><pre>     } <strong>else</strong> <strong>if</strong>  i % 2 == 1 , j % 2 != 1 {</pre><pre>            showlabel = showlabel + &quot;🍎&quot;</pre><pre>     } <strong>else</strong> {</pre><pre>            showlabel = showlabel + &quot;⭐️&quot;</pre><pre>        }</pre><pre>     }</pre><pre>            showlabel = showlabel + &quot;\n&quot;</pre><pre>}</pre><pre>  label.text = showlabel</pre><pre>  showslider.text = &quot;\(number)&quot;</pre><p>完整程式Github</p><p><a href="https://github.com/Chingwenluo/Nested-Loop">Chingwenluo/Nested-Loop</a></p><p>參考資料:</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/60-%E7%95%AB%E6%98%9F%E6%98%9F%E8%98%8B%E6%9E%9C-d48c41b808a">#60 畫星星蘋果</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/28-%E7%95%AB%E6%98%9F%E6%98%9F%E8%98%8B%E6%9E%9C-nested-loop-%E5%B7%A2%E7%8B%80%E8%BF%B4%E5%9C%88-%E7%B7%B4%E7%BF%92-c8603f4db0e1">#28 畫星星蘋果 — nested loop(巢狀迴圈) 練習</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/60-%E7%95%AB%E6%98%9F%E6%98%9F%E8%98%8B%E6%9E%9C-nested-loop-%E7%B7%B4%E7%BF%92-8321d8fbcc51">#60 畫星星蘋果 — nested loop 練習</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6beadc6b492" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%AD%B8%E7%BF%92%E8%A8%98%E9%8C%84-60-%E7%95%AB%E6%98%9F%E6%98%9F%E8%98%8B%E6%9E%9C-nested-loop-%E5%B7%A2%E7%8B%80%E8%BF%B4%E5%9C%88-c6beadc6b492">學習記錄#60 畫星星蘋果 — nested loop(巢狀迴圈)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>