<?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 Yi Ting Sung on Medium]]></title>
        <description><![CDATA[Stories by Yi Ting Sung on Medium]]></description>
        <link>https://medium.com/@ting3242006?source=rss-a07aa3bd2213------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q70f1Y6vwZIBi4BQW6Z2dw.jpeg</url>
            <title>Stories by Yi Ting Sung on Medium</title>
            <link>https://medium.com/@ting3242006?source=rss-a07aa3bd2213------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:46:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ting3242006/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[Swift|26 植物購物 App]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-26-%E6%A4%8D%E7%89%A9%E8%B3%BC%E7%89%A9-app-bb342f2f30cf?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb342f2f30cf</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Tue, 15 Feb 2022 17:51:51 GMT</pubDate>
            <atom:updated>2022-02-17T10:26:04.042Z</atom:updated>
            <content:encoded><![CDATA[<p>把購物app結合我平常的嗜好-植物🌳</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmS5NdfOyPR4Rgyelsyn5Q.jpeg" /></figure><p>運用：UIStepper、IBAction、 IBOutlet、Scroll View水平捲動和分頁、Label、Button、Image View、數字變字串</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*LAIwy0BPM_wzXK70teIMjQ.gif" /><figcaption>成果</figcaption></figure><blockquote><strong><em>設定Scroll View</em></strong></blockquote><p>把會用到的物件設定好，商品選單放在Scroll View裡。<br>將View 先拉出 Exit 之外方便編輯，編輯完成再將 View 拉回 Scroll View 裡，拉進去之後，座標會在奇怪的位置，重新設定 View 的 X 和 Y，可以看到View出現在 scroll view 上。細節如下：</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-storyboard-%E8%A8%AD%E5%AE%9A-content-size-%E5%AF%A6%E7%8F%BE%E6%B0%B4%E5%B9%B3%E6%8D%B2%E5%8B%95%E7%9A%84-scroll-view-2710fa247293">設定 content size，實現水平捲動，上下捲動和分頁的 scroll view</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*xKhreXG3_CIHoo8DKHvOJw.png" /><figcaption>將View 先拉出 Exit 之外方便編輯</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHnKLVuptR-8capRQAJ7aA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*93SaJypmHIeLJGMO8555SQ.png" /><figcaption>編輯完成再將 View 拉回 Scroll View 裡</figcaption></figure><blockquote><strong><em>拉IBAction、 IBOutlet</em></strong></blockquote><p>將各個產品數量、產品價格、總價的Label和Stepper拉上 IBOutlet</p><pre>//數量</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> CatusQtyTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SnackQtyTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> FigQtyTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SucculentQtyTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AnthuQtyTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AglaoQtyTextField: UILabel!</pre><pre>//價格</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> CatusPriceTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SnackPriceTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> FigPriceTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SucculentPriceTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AnthuPriceTextField: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AglaoPriceTextField: UILabel!</pre><pre>//Stepper</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> CatusStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SnackStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> FigStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> SucculentStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AnthuStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> AglaoStepper: UIStepper!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> totalLabel: UILabel!</pre><p>將每個產品的Stepper連上同一個IBAction，Stepper的數值傳到顯示產品數量的Text Field (QtyTextField) 裡。</p><p>再連一個IBAction，點Ｘ圖示的Button可以清空購物車。</p><pre><strong>@IBAction</strong> <strong>func</strong> changeQty(_ sender: UIStepper) {</pre><pre>itemCatus = Int(CatusStepper.value)</pre><pre>itemSnack = Int(SnackStepper.value)</pre><pre>itemFig = Int(FigStepper.value)</pre><pre>itemSucculent = Int(SucculentStepper.value)</pre><pre>itemAnthu = Int(AnthuStepper.value)</pre><pre>itemAglao = Int(AglaoStepper.value)</pre><pre>CatusQtyTextField.text = String(itemCatus)</pre><pre>SnackQtyTextField.text = String(itemSnack)</pre><pre>FigQtyTextField.text = String(itemFig)</pre><pre>SucculentQtyTextField.text = String(itemSucculent)</pre><pre>AnthuQtyTextField.text = String(itemAnthu)</pre><pre>AglaoQtyTextField.text = String(itemAglao)</pre><pre>calculate()</pre><pre>}</pre><pre>//清除購物車 將數值歸零</pre><pre><strong>@IBAction</strong> <strong>func</strong> clearAll(_ sender: UIButton) {</pre><pre>CatusStepper.value = 0</pre><pre>SnackStepper.value = 0</pre><pre>FigStepper.value = 0</pre><pre>SucculentStepper.value = 0</pre><pre>AnthuStepper.value = 0</pre><pre>AglaoStepper.value = 0</pre><pre>CatusQtyTextField.text = &quot;0&quot;</pre><pre>SnackQtyTextField.text = &quot;0&quot;</pre><pre>FigQtyTextField.text = &quot;0&quot;</pre><pre>SucculentQtyTextField.text = &quot;0&quot;</pre><pre>AnthuQtyTextField.text = &quot;0&quot;</pre><pre>AglaoQtyTextField.text = &quot;0&quot;</pre><pre>totalLabel.text = &quot;0&quot;</pre><pre>}</pre><blockquote><strong><em>建立儲存數量的變數</em></strong></blockquote><pre><strong>var</strong> itemCatus:Int = 0</pre><pre><strong>var</strong> itemSnack:Int = 0</pre><pre><strong>var</strong> itemFig:Int = 0</pre><pre><strong>var</strong> itemSucculent:Int = 0</pre><pre><strong>var</strong> itemAnthu:Int = 0</pre><pre><strong>var</strong> itemAglao:Int = 0</pre><blockquote><strong><em>設定顯示價格</em></strong></blockquote><p>把商品價格放到viewDidLoad裡</p><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>CatusPriceTextField.text = &quot;99&quot;</pre><pre>SnackPriceTextField.text = &quot;999&quot;</pre><pre>FigPriceTextField.text = &quot;1299&quot;</pre><pre>SucculentPriceTextField.text = &quot;599&quot;</pre><pre>AnthuPriceTextField.text = &quot;880&quot;</pre><pre>AglaoPriceTextField.text = &quot;499&quot;</pre><pre>}</pre><blockquote><strong><em>計算金額的公式</em></strong></blockquote><p>因為金額是新台幣，沒有小數點，所以用Int來轉字串，如果有小數點可以用Float來轉。</p><pre><strong>func</strong> calculate(){</pre><pre>//字串轉數字</pre><pre><strong>let</strong> CatusPrice = Int(CatusPriceTextField.text!)!</pre><pre><strong>let</strong> SnackPrice = Int(SnackPriceTextField.text!)!</pre><pre><strong>let</strong> FigPrice = Int(FigPriceTextField.text!)!</pre><pre><strong>let</strong> SucculentPrice = Int(SucculentPriceTextField.text!)!</pre><pre><strong>let</strong> AnthuPrice = Int(AnthuPriceTextField.text!)!</pre><pre><strong>let</strong> AglaoPrice = Int(AglaoPriceTextField.text!)!</pre><pre>//統計 金額x數量</pre><pre><strong>let</strong> sum = CatusPrice * Int(itemCatus) + SnackPrice * Int(itemSnack) + FigPrice * Int(itemFig) + SucculentPrice * Int(itemSucculent) + AnthuPrice * Int(itemAnthu) + AglaoPrice * Int(itemAglao)</pre><pre>totalLabel.text = &quot;\(sum)&quot;</pre><pre>}</pre><blockquote><strong><em>全部結帳金額顯示</em></strong></blockquote><p>將這個計算公式的function calculate()加入<strong>@IBAction</strong> <strong>func</strong> changeQty(_ sender: UIStepper) {}內，點擊Stepper時可以同時改變購物車的金額。</p><pre>totalLabel.text = &quot;\(sum)&quot;</pre><h3>參考資料</h3><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%E6%95%99%E5%AE%A4/51-%E9%98%B2%E7%96%AB%E7%94%9F%E9%AE%AE%E8%B3%BC%E7%89%A9-app-uistepper-%E5%92%8C%E6%95%B8%E5%AD%97%E8%AE%8A%E5%AD%97%E4%B8%B2-104d63928cfa">#51 防疫生鮮購物 App — UIStepper 和數字變字串</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/%E6%99%82%E5%B0%9A%E8%B3%BC%E7%89%A9-app-%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84ios-app-%E4%BD%9C%E6%A5%AD-fb170c01f1c0">#11 瘋狂購物 App — UIStepper 和數字變字串練習</a></li></ul><h3>GitHub</h3><p><a href="https://github.com/ting3242006/shoppingApp">GitHub - ting3242006/shoppingApp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb342f2f30cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-26-%E6%A4%8D%E7%89%A9%E8%B3%BC%E7%89%A9-app-bb342f2f30cf">Swift|26 植物購物 App</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[Swift|25 利用 page control，segmented control，button & gesture 更換內容]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-25-%E5%88%A9%E7%94%A8-page-control-segmented-control-button-gesture-%E6%9B%B4%E6%8F%9B%E5%85%A7%E5%AE%B9-f578b9e4dd1c?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/f578b9e4dd1c</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Fri, 04 Feb 2022 08:10:30 GMT</pubDate>
            <atom:updated>2022-02-17T16:54:12.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WRtLczG1a7_pjY0E91OL2A.jpeg" /></figure><h4>運用元件切換來顯示今敏大師的三部動畫電影作品</h4><ul><li>Image View</li><li>Segment Control</li><li>Page Control</li><li>Label</li><li>Prev、Next Button</li><li>Swipe Gesture Recognizer</li></ul><h4>程式碼</h4><p>把page control、segmented control、label &amp; image view拉outlet出來，<br>另外有將image view設圓角</p><pre>//拉outlet</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> movieImageView: UIImageView!{</pre><pre><strong>didSet</strong> {</pre><pre>movieImageView.layer.cornerRadius = 30</pre><pre>movieImageView.clipsToBounds = <strong>true</strong></pre><pre>}</pre><pre>}</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> movieSegment: UISegmentedControl!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> moviePageControl: UIPageControl!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> movieLabel: UILabel!</pre><p>將資料儲存在imageViews、movieDescriptions的Label陣列中，<br>並定義一個型別為Int的變數，用於之後顯示陣列的排序</p><pre>//運用陣列array</pre><pre><strong>let</strong> imageViews = [&quot;actress&quot;,&quot;blue&quot;,&quot;godFather&quot;]</pre><pre><strong>let</strong> movieDescriptions = [&quot;以主角藤原千代子一生時緊時鬆的追夢，貫穿演藝人生；而她所演出的每一部電影，全都為其終生的追尋作註解。&quot;, &quot;霧越未麻是流行音樂偶像團體「CHAM!」中的成員之一，但是在公司的決策下，未麻告別偶像身分轉往演員發展。但她卻感覺內心有個聲音在拒絕自己的選擇。隨著越來越多電視劇的演出，未麻卻覺得自己的頭腦越來越奇怪，彷彿有「另一個自己」正在形成。這時，她身邊的工作人員竟一個個接連被殺。在面對社會壓力和疑雲之際，未麻感到越來越混亂……&quot;, &quot;大雪紛飛的東京，在一個原本應該是全家團圓的聖誕夜裡，流浪漢阿仁、小花和美雪卻在新宿街頭意外撿到一個被遺棄的女嬰。三個看似放棄人生，沒有未來的流浪漢在叢林都市中展開了一段尋人冒險。&quot;]</pre><pre>//顯示陣列排序</pre><pre><strong>var index:Int = 0</strong></pre><p>每呼叫一次pageChange()，就會顯示func定義的內容</p><pre>//function定義同步改變的內容</pre><pre><strong>func</strong> pageChange(){</pre><pre>movieImageView.image = UIImage(named: imageViews[index])</pre><pre>movieSegment.selectedSegmentIndex = index</pre><pre>moviePageControl.currentPage = index</pre><pre>movieLabel.text = movieDescriptions[index]</pre><pre>}</pre><p>Segment Control和Page Control的設定</p><pre>//Segment Control切換</pre><pre><strong>@IBAction</strong> <strong>func</strong> selectSegment(_ sender: <strong>Any</strong>) {</pre><pre>index = movieSegment.selectedSegmentIndex</pre><pre>pageChange()</pre><pre>}</pre><pre>//下一頁</pre><pre><strong>@IBAction</strong> <strong>func</strong> next(_ sender: <strong>Any</strong>) {</pre><pre><strong>if</strong> index == imageViews.count-1 {</pre><pre>index = 0</pre><pre>}<strong>else</strong>{</pre><pre>index += 1</pre><pre>}</pre><pre>pageChange()</pre><pre>}</pre><pre>//前一頁</pre><pre><strong>@IBAction</strong> <strong>func</strong> pre(_ sender: <strong>Any</strong>) {</pre><pre><strong>if</strong> index == 0 {</pre><pre>index = imageViews.count-1</pre><pre>}<strong>else</strong>{</pre><pre>index -= 1</pre><pre>}</pre><pre>pageChange()</pre><pre>}</pre><pre>//Page Control切換</pre><pre><strong>@IBAction</strong> <strong>func</strong> changePage(_ sender: <strong>Any</strong>) {</pre><pre>index = moviePageControl.currentPage</pre><pre>pageChange()</pre><pre>}</pre><p>向左向右滑的Gesture設定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F3cl0TDh3adX4-auSSGSJA.png" /><figcaption>將 Gesture Recognizer 加到想辨識手勢的元件上，拖曳到 storyboard 上的 image view。</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*hBoapG52J1FK__2NB6oA0A.png" /><figcaption>元件列表裡將長出 Swipe Gesture Recognizer，我們需要加入兩個，一個向左、一個向右</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*oTYDHlR8tzITL-D5LCjEGw.png" /><figcaption>一個設定Left，一個設定Right</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*3-K6osnY0jU4NiLhPKa0Zw.png" /></figure><p>想讓 image view 觸碰有反應，能辨識到 swipe 手勢，我們要將它的 User Interaction Enabled 勾選。</p><p>從 storyboard 的 gesture recognizer 元件拉 IBAction，設定手勢辨識執行的 function。</p><pre>//向左、向右滑動翻頁</pre><pre><strong>@IBAction</strong> <strong>func</strong> SwipeToChange(_ sender: UISwipeGestureRecognizer) {</pre><pre><strong>if</strong> sender.direction == .left {</pre><pre>index += 1</pre><pre><strong>if</strong> index == 0 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> <strong>if</strong> index == 1 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> <strong>if</strong> index == 2 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> {</pre><pre>index = 0</pre><pre>pageChange()</pre><pre>}</pre><pre>}<strong>else</strong> <strong>if</strong> sender.direction == .right {</pre><pre>index -= 1</pre><pre><strong>if</strong> index == 2 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> <strong>if</strong> index == 1 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> <strong>if</strong> index == 0 {</pre><pre>pageChange()</pre><pre>} <strong>else</strong> {</pre><pre>index = 2</pre><pre>pageChange()</pre><pre>}</pre><pre>}</pre><pre>}</pre><h4>成果</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*vt_zlNTeL8y_vMEla6LTlw.gif" /></figure><h4>參考</h4><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/%E7%9C%9F%E6%84%9B%E7%9A%84%E6%A8%A1%E6%A8%A3-image-view-%E5%92%8C-segmented-control-%E7%B7%B4%E7%BF%92-675d64d5c94c">#38 利用 page control，segmented control，button &amp; gesture 更換內容</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/%E9%81%8B%E7%94%A8-page-control-segmented-control-button-gesture-%E6%84%9B%E5%9C%A8%E4%B8%89%E9%83%A8%E6%9B%B2-c285cd4f1523">運用 page control、segmented control、button &amp; gesture — 愛在三部曲</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/9-%E5%88%A9%E7%94%A8-button-gesture-%E6%9B%B4%E6%8F%9B%E5%9C%96%E7%89%87%E5%85%A7%E5%AE%B9-9a34e84e9cc9">#9 利用 button &amp; gesture 更換圖片內容</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-page-control-segmented-control-button-gesture-%E6%9B%B4%E6%8F%9B%E5%85%A7%E5%AE%B9-f3b7cf3c918">利用 page control，segmented control，button &amp; gesture 更換內容</a></li></ul><h4>GitHub</h4><p><a href="https://github.com/ting3242006/changeImage">GitHub - ting3242006/changeImage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f578b9e4dd1c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-25-%E5%88%A9%E7%94%A8-page-control-segmented-control-button-gesture-%E6%9B%B4%E6%8F%9B%E5%85%A7%E5%AE%B9-f578b9e4dd1c">Swift|25 利用 page control，segmented control，button &amp; gesture 更換內容</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[Swift|24 利用 mask 設計特別形狀的圖片及影片]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-24-%E5%88%A9%E7%94%A8-mask-%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%E5%8F%8A%E5%BD%B1%E7%89%87-748a89d97ff?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/748a89d97ff</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Sun, 30 Jan 2022 14:52:39 GMT</pubDate>
            <atom:updated>2022-02-04T08:13:34.755Z</atom:updated>
            <content:encoded><![CDATA[<p>練習：image view 的 mask，<br>用下面兩張圖片來融合成在攝影機裡播放鬥陣俱樂部</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQwPl7YdFZPGbeG45UdkPQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*wQNPBBfIbn4X81VPuxR7bg.png" /></figure><blockquote><strong><em>先在preview app裡做去背，留下攝影機的黑色區塊</em></strong></blockquote><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%A6%82%E4%BD%95%E7%94%A8-previe-app-%E9%A0%90%E8%A6%BD%E7%A8%8B%E5%BC%8F-%E5%8E%BB%E8%83%8C%E5%9C%96%E7%89%87-f44640424ba2">如何用 Preview App (預覽程式)去背圖片</a></p><blockquote><strong><em>把圖片加入Playground裡</em></strong></blockquote><p>把素材從Finder拖放到Resources底下</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*gvhDV_ikdzQV6PZ0XuGzLg.png" /></figure><blockquote><strong><em>打上程式碼</em></strong></blockquote><pre><strong>import</strong> UIKit</pre><ol><li>加入 UIKit這個函式庫，因為我們要使用UI 相關的程式，例如UIImage 和 UIImageView 。</li></ol><pre><strong>let</strong> fightclubImage = UIImage(named: &quot;fight club.jpeg&quot;)</pre><pre><strong>let</strong> fightclubImageView = UIImageView(image: fightclubImage)</pre><pre><strong>let</strong> cinemaImage = UIImage(named: &quot;cinema.png&quot;)</pre><pre><strong>let</strong> cinemaImageView = UIImageView(image: cinemaImage)</pre><p>2. 產生顯示fight club和攝影機的image view</p><pre>fightclubImageView.mask = cinemaImageView</pre><p>3. 設定鬥陣俱樂部的mask是攝影機圖案</p><blockquote><strong><em>結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*_i_AOE4FF54JogyRRbMYCQ.png" /></figure><h3><em>用 SF Symbols 的 image view 當 mask</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3inrw7EDrCFo1bKy_SiXw.png" /><figcaption>SF Symbols</figcaption></figure><pre><strong>let</strong> fightclubImage = UIImage(named: &quot;fight club.jpeg&quot;)</pre><pre><strong>let</strong> fightclubImageView = UIImageView(image: fightclubImage)</pre><pre>fightclubImageView.frame = CGRect(x: 0, y: 0, width: 750, height: 500)</pre><pre><strong>let</strong> tvImageView = UIImageView(image: UIImage(systemName: &quot;tv.inset.filled&quot;))</pre><pre>tvImageView.frame = fightclubImageView.frame</pre><pre>fightclubImageView.mask = tvImageView</pre><blockquote><strong><em>結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*122eHUIAiVzLMbeWAitbqg.png" /></figure><h3>用label來做mask</h3><pre><strong>import</strong> UIKit</pre><pre><strong>let</strong> fightclubImage = UIImage(named: &quot;fight club.jpeg&quot;)</pre><pre><strong>let</strong> fightclubImageView = UIImageView(image: fightclubImage)</pre><pre><strong>let</strong> label = UILabel(frame: fightclubImageView.frame)</pre><pre>label.text = &quot;$&quot;</pre><pre>label.font = UIFont.systemFont(ofSize: 600)</pre><pre>label.textAlignment = NSTextAlignment.center</pre><pre>fightclubImageView.mask = label</pre><blockquote><strong><em>結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*Q7dmAn2zpn8gARHHXonEBA.png" /></figure><h3>漸層mask</h3><pre><strong>import</strong> UIKit</pre><pre><strong>let</strong> fightclubImage = UIImage(named: &quot;fight club.jpeg&quot;)</pre><pre><strong>let</strong> fightclubImageView = UIImageView(image: fightclubImage)</pre><pre><strong>let</strong> gradietLayer = CAGradientLayer()</pre><pre>gradietLayer.frame = fightclubImageView.bounds</pre><pre>gradietLayer.colors = [CGColor(red: 1, green: 1, blue: 1, alpha: 0), CGColor(red: 1, green: 1, blue: 1, alpha: 1)]</pre><pre>gradietLayer.startPoint = CGPoint(x: 0, y: 0)</pre><pre>gradietLayer.endPoint = CGPoint(x: 0, y: 1)</pre><pre>fightclubImageView.layer.mask = gradietLayer</pre><pre>fightclubImageView</pre><blockquote><strong><em>結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*mHu9hhC4iWkSSyTzHJI6LQ.png" /></figure><h3>利用mask 改變圖片的顏色</h3><p>為圖片加一點藍綠色</p><pre><strong>import</strong> UIKit</pre><pre><strong>let</strong> fightclubImage = UIImage(named: &quot;fight club.jpeg&quot;)</pre><pre><strong>let</strong> fightclubImageView = UIImageView(image: fightclubImage)</pre><pre><strong>let</strong> cinemaImage = UIImage(named: &quot;cinema.png&quot;)</pre><pre><strong>let</strong> cinemaImageView1 = UIImageView(image: cinemaImage)</pre><pre>fightclubImageView.mask = cinemaImageView1</pre><pre><strong>let</strong> blueView = UIView(frame: fightclubImageView.frame)</pre><pre>blueView.backgroundColor = UIColor(red: 0, green: 0.5, blue: 1, alpha: 0.5)</pre><pre><strong>let</strong> cinemaImageView2 = UIImageView(image: cinemaImage)</pre><pre>blueView.mask = cinemaImageView2</pre><pre>fightclubImageView.addSubview(blueView)</pre><blockquote><strong><em>結果</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*JSeV9-sDtscrBCv1pjMB_w.png" /></figure><h3>練習用AVPlayerLayer 的 mask 播放預告</h3><pre><strong>import</strong> UIKit</pre><pre><strong>import</strong> AVFoundation</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>//加入攝影機圖片</pre><pre><strong>let</strong> cinemaImage = UIImage(named: &quot;cinema.png&quot;)</pre><pre><strong>let</strong> cinemaImageView = UIImageView(image: cinemaImage)</pre><pre>//設定攝影機圖片大小</pre><pre>cinemaImageView.frame.size = CGSize(width: 800, height: 425)</pre><pre>//設定影像的位置和大小</pre><pre><strong>let</strong> videoView = UIView(frame: CGRect(origin: CGPoint(x: -10, y: -25), size: cinemaImageView.frame.size))</pre><pre>//videoView用來裝呈現影片的layer，cinemaImageView會當作videoView的mask</pre><pre>view.addSubview(videoView)</pre><pre>//加入影片的URL</pre><pre><strong>let</strong> url = URL(string: &quot;http://movietrailers.apple.com/movies/wb/madmaxfuryroad/madmax-tlr3_h1080p.mov&quot;)</pre><pre><strong>let</strong> player = AVPlayer(url: url!)</pre><pre>//顯示到畫面上需要型別AVPlayerLayer的playerLayer</pre><pre>//如果只有player，我們只能聽到聲音</pre><pre><strong>let</strong> playerLayer = AVPlayerLayer(player: player)</pre><pre>playerLayer.frame = CGRect(origin: .zero, size: cinemaImageView.frame.size)</pre><pre>//.resizeAspectFill讓影片佔滿playerLayer的長方形框框</pre><pre>playerLayer.videoGravity = .resizeAspectFill</pre><pre>//將顯示影片的playerLayer加到videoView上</pre><pre>videoView.layer.addSublayer(playerLayer)</pre><pre>//videoView原本是長方形，透過設定mask為cinemaImageView，讓videoView切成攝影機形狀</pre><pre>videoView.mask = cinemaImageView</pre><pre>//播放</pre><pre>player.play()</pre><pre>}</pre><pre>}</pre><blockquote><strong><em>預告影片網址取得url</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLi-LJsNLgD-3_MQfDLb2w.png" /><figcaption>在想要的畫質按右鍵，選Copy Link Address</figcaption></figure><p><a href="https://www.hd-trailers.net/movie/mad-max-fury-road/">Mad Max: Fury Road</a></p><blockquote><strong><em>結果</em></strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAQecPIgbeNY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAQecPIgbeNY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAQecPIgbeNY%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/cb29fe7be1c1e07fec3864395bd4bec2/href">https://medium.com/media/cb29fe7be1c1e07fec3864395bd4bec2/href</a></iframe><h3>參考</h3><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-uiview-%E7%9A%84-mask-%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-4e22cd7c3fbe">利用 UIView 的 mask 設計特別形狀的圖片</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/%E4%BD%9C%E6%A5%AD-13-%E5%88%A9%E7%94%A8mask%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-%E5%BD%B1%E7%89%87-994766c51e61">作業#13 利用mask設計特別形狀的圖片＆影片</a></li></ul><h3>GitHub</h3><p><a href="https://github.com/ting3242006/mask-on-video">https://github.com/ting3242006/mask-on-video</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=748a89d97ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-24-%E5%88%A9%E7%94%A8-mask-%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%E5%8F%8A%E5%BD%B1%E7%89%87-748a89d97ff">Swift|24 利用 mask 設計特別形狀的圖片及影片</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[Swift|23 iOS SDK顯示地圖和地圖標記的方法]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-23-ios-sdk%E9%A1%AF%E7%A4%BA%E5%9C%B0%E5%9C%96%E5%92%8C%E5%9C%B0%E5%9C%96%E6%A8%99%E8%A8%98%E7%9A%84%E6%96%B9%E6%B3%95-3552c32dbabd?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/3552c32dbabd</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 13:53:00 GMT</pubDate>
            <atom:updated>2022-01-22T13:53:00.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NcxycZcq0yp0uPRt.jpg" /><figcaption>photo : W Workspace</figcaption></figure><p>最近看到泰國大城新開了一家購物商場<br>從 Xcode 的 playground 練習<br>利用 MKMapView 顯示地圖帶我去線上遊覽吧！<br>好想出國(〒︿〒)</p><blockquote><strong><em>先查出地點的經緯度</em></strong></blockquote><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-mac-%E7%9A%84-maps-app-%E6%9F%A5%E8%A9%A2%E7%B6%93%E7%B7%AF%E5%BA%A6%E7%9A%84%E5%85%A9%E5%80%8B%E6%96%B9%E6%B3%95-3dff7ad0847f">利用 Mac 的 Maps App 查詢經緯度的兩個方法</a></p><blockquote><strong><em>在Playground裡要看到顯示controller的view</em></strong></blockquote><p>需要使用live view</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-xcode-playground-%E7%9A%84-live-view-%E9%A1%AF%E7%A4%BA-controller-f9b20591857f">利用 Xcode playground 的 live view 顯示 App 畫面</a></p><blockquote><strong><em>在playground 加入 framework MapKit</em></strong></blockquote><pre><strong>import</strong> MapKit</pre><pre>//為了在playground看到地圖</pre><pre><strong>import</strong> PlaygroundSupport</pre><pre><strong>let</strong> mapView = MKMapView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))</pre><pre>//顯示地圖經緯度和範圍</pre><pre>mapView.region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 14.331622, longitude: 100.611817), latitudinalMeters: 1000, longitudinalMeters: 1000)</pre><blockquote><strong><em>顯示地圖中心點的經緯度和範圍</em></strong></blockquote><p>用mapView的region(區域)顯示地圖中心點和經緯度，<br>型別為MKCoordinateRegion，要輸入以下三種參數：</p><p>latitude 是緯度，longitude 是經度</p><ul><li>latitudinalMeters — 緯度範圍，單位是公尺<br>因此我們寫入 1000， 表示地圖的最北邊和最南邊距離 1000 公尺</li><li>longitudinalMeters — 經度範圍，單位是公尺<br>因此我們寫入 1000 表示地圖的最東邊和最西邊距離 1000 公尺</li></ul><blockquote><strong><em>用 MKPointAnnotation加入地點標記</em></strong></blockquote><p>可以加入標題(title)和副標題(subtitle)</p><pre><strong>let</strong> AyutthayaShoppingMall = MKPointAnnotation()</pre><pre>AyutthayaShoppingMall.title = &quot;Central Ayutthaya&quot;</pre><pre>AyutthayaShoppingMall.coordinate = CLLocationCoordinate2D(latitude: 14.331622, longitude: 100.611817)</pre><pre>AyutthayaShoppingMall.subtitle = &quot;大城新開的百貨公司&quot;</pre><pre>mapView.addAnnotation(AyutthayaShoppingMall)</pre><pre>PlaygroundPage.current.liveView = mapView</pre><blockquote><strong><em>結果顯示如下</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*CNyiY9PL79DAxNtaVpahaA.png" /></figure><blockquote><strong><em>改變地圖顯示模式</em></strong></blockquote><pre>mapView.mapType = .hybrid</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*_6wCPDxsAqgKDBHzL18zbg.png" /><figcaption>衛星空照加地圖模式</figcaption></figure><pre>mapView.mapType = .satellite</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*T2e5K9UwHq-LnrYlpjTF-w.png" /><figcaption>衛星空照模式</figcaption></figure><h3>參考資料</h3><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/ios-sdk-%E9%A1%AF%E7%A4%BA%E5%9C%B0%E5%9C%96-%E5%9C%B0%E5%9C%96%E6%A8%99%E8%A8%98%E7%9A%84%E6%96%B9%E6%B3%95-7b284e48a446">iOS SDK 顯示地圖 &amp; 地圖標記的方法</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3552c32dbabd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-23-ios-sdk%E9%A1%AF%E7%A4%BA%E5%9C%B0%E5%9C%96%E5%92%8C%E5%9C%B0%E5%9C%96%E6%A8%99%E8%A8%98%E7%9A%84%E6%96%B9%E6%B3%95-3552c32dbabd">Swift|23 iOS SDK顯示地圖和地圖標記的方法</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[Swift|22 撲克牌比大小遊戲]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-22-%E6%92%B2%E5%85%8B%E7%89%8C%E6%AF%94%E5%A4%A7%E5%B0%8F%E9%81%8A%E6%88%B2-9191fab927e0?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/9191fab927e0</guid>
            <category><![CDATA[poker]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Sat, 23 Oct 2021 07:40:17 GMT</pubDate>
            <atom:updated>2021-10-23T15:02:51.803Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycKnSsEXL2jChZD8LXng4Q.jpeg" /></figure><h3>使用元件</h3><ul><li>Image View</li><li>Label</li><li>Button</li><li>Stepper</li></ul><h3>遊戲玩法</h3><ul><li>撲克牌A最小，K最大</li><li>玩家原本有一千元，猜對增加一百元，猜錯減少一百元</li><li>玩家可以決定壓注的金額</li><li>金額在零或零以下遊戲結束</li><li>按Replay重新開始遊戲</li></ul><blockquote><strong><em>定義撲克牌型別</em></strong></blockquote><p>把花色(suit)和數字大小(rank)分不同的array</p><pre><strong>import</strong> Foundation</pre><pre><strong>struct</strong> Card {</pre><pre><strong>var</strong> suit:String</pre><pre><strong>var</strong> rank:String</pre><pre>}</pre><pre><strong>let</strong> suits = [&quot;♣️&quot;, &quot;♦️&quot;, &quot;♥️&quot;, &quot;♠️&quot;]</pre><pre><strong>let</strong> ranks = [&quot;A&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;, &quot;J&quot;, &quot;Q&quot;, &quot;K&quot;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*GH1f5-bWLbPw_D2QHn_mAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*hPPLZlwnxR6jbQKJlCwwWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*jKZAMjhph7Stl8IaYvgTfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KqmE5Xr5nc7FwS4t6rZaww.png" /><figcaption>把變數或常數放在最外面，全部地方都可以使用</figcaption></figure><blockquote><strong><em>拉IBOutlet &amp; IBAction</em></strong></blockquote><pre><strong>import</strong> UIKit</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> computerCardLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> playerCardLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> resultLabel: UILabel!</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> play(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>}</pre><p>寫一個撲克牌的Array，裡面沒有裝東西</p><p>52張牌的兩層Loop寫法(Nested Loop)</p><pre><strong>var</strong> cards = [Card]()<br></pre><pre><strong>func</strong> creatCards(){</pre><pre><strong>for</strong> suit <strong>in</strong> suits {</pre><pre><strong>for</strong> rank <strong>in</strong> ranks {</pre><pre><strong>let</strong> card = Card(suit: suit, rank: rank)</pre><pre>cards.append(card)</pre><pre>}</pre><pre>}</pre><pre>}</pre><blockquote><strong><em>在ViewDidLoad呼叫出撲克牌</em></strong></blockquote><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>creatCards()</pre><pre>}</pre><blockquote><strong><em>Play按下去之後</em></strong></blockquote><p>先洗牌(shuffle)<br>第一張牌先發給電腦<br>第二張牌再發給玩家</p><pre>cards.shuffle()</pre><pre><strong>let</strong> computerCard = cards[0]</pre><pre>computerCardLabel.text = &quot;\(computerCard.suit) \(computerCard.rank)&quot;</pre><pre><strong>let</strong> playerCard = cards[1]</pre><pre>playerCardLabel.text = &quot;\(playerCard.suit) \(playerCard.rank)&quot;</pre><blockquote><strong><em>用 if else 來比大小</em></strong></blockquote><p>因為電腦會用字串來比大小<br>英文字母排列J&lt;K&lt;Q<br>所以我們要幫撲克牌打分數來比大小<br>設A為最小，J為11，Q為12，K為13</p><p>其他的數字用Int把字串轉數字<br>因為有可能是nil<br>所以使用optional</p><pre><strong>var</strong> compuerCardNumber = 0</pre><pre><strong>if</strong> computerCard.rank == &quot;A&quot;{</pre><pre>compuerCardNumber = 1</pre><pre>}<strong>else</strong> <strong>if</strong> computerCard.rank == &quot;J&quot;{</pre><pre>compuerCardNumber = 11</pre><pre>}<strong>else</strong> <strong>if</strong> computerCard.rank == &quot;Q&quot;{</pre><pre>compuerCardNumber = 12</pre><pre>}<strong>else</strong> <strong>if</strong> computerCard.rank == &quot;K&quot;{</pre><pre>compuerCardNumber = 13</pre><pre>}<strong>else</strong>{</pre><pre>compuerCardNumber = Int(computerCard.rank)!</pre><pre>}</pre><pre><strong>var</strong> playerCardNumber = 0</pre><pre><strong>if</strong> playerCard.rank == &quot;A&quot;{</pre><pre>playerCardNumber = 1</pre><pre>}<strong>else</strong> <strong>if</strong> playerCard.rank == &quot;J&quot;{</pre><pre>playerCardNumber = 11</pre><pre>}<strong>else</strong> <strong>if</strong> playerCard.rank == &quot;Q&quot;{</pre><pre>playerCardNumber = 12</pre><pre>}<strong>else</strong> <strong>if</strong> playerCard.rank == &quot;K&quot;{</pre><pre>playerCardNumber = 13</pre><pre>}<strong>else</strong>{</pre><pre>playerCardNumber = Int(playerCard.rank)!</pre><pre>}</pre><blockquote><strong><em>比完數字，再比花色</em></strong></blockquote><pre><strong>if</strong> compuerCardNumber &lt; playerCardNumber{</pre><pre>resultLabel.text = &quot;You Win&quot;</pre><pre>}<strong>else</strong> <strong>if</strong> compuerCardNumber &gt; playerCardNumber{</pre><pre>resultLabel.text = &quot;You Lose&quot;</pre><pre>}<strong>else</strong> {</pre><pre><strong>var</strong> playerSuitNumber = 0</pre><pre><strong>if</strong> playerCard.suit == &quot;♣️&quot;{</pre><pre>playerCardNumber = 1</pre><pre>}<strong>else</strong> <strong>if</strong> playerCard.suit == &quot;♦️&quot;{</pre><pre>playerCardNumber = 2</pre><pre>}<strong>else</strong> <strong>if</strong> playerCard.suit == &quot;♥️&quot;{</pre><pre>playerCardNumber = 3</pre><pre>}<strong>else</strong>{</pre><pre>playerCardNumber = 4</pre><pre>}</pre><pre><strong>var</strong> computerSuitNumber = 0</pre><pre><strong>if</strong> computerCard.suit == &quot;♣️&quot;{</pre><pre>compuerCardNumber = 1</pre><pre>}<strong>else</strong> <strong>if</strong> computerCard.suit == &quot;♦️&quot;{</pre><pre>compuerCardNumber = 2</pre><pre>}<strong>else</strong> <strong>if</strong> computerCard.suit == &quot;♥️&quot;{</pre><pre>compuerCardNumber = 3</pre><pre>}<strong>else</strong>{</pre><pre>compuerCardNumber = 4</pre><pre>}</pre><blockquote><strong><em>輸贏後在結果欄中顯示文字，以及改變本金金額</em></strong></blockquote><pre><strong>if</strong> computerSuitNumber &lt; playerSuitNumber {</pre><pre>resultLabel.text = &quot;You Win!&quot;</pre><pre>playerMoneyLabel.text = &quot;\(playerMoney + bet)&quot;</pre><pre>} <strong>else</strong> {</pre><pre>resultLabel.text = &quot;You Lose&quot;</pre><pre>playerMoneyLabel.text = &quot;\(playerMoney - bet)&quot;</pre><pre>}</pre><blockquote><strong><em>本金少於等於0，遊戲結束</em></strong></blockquote><pre>playerMoney = Int(playerMoneyLabel.text!)!</pre><pre><strong>if</strong> playerMoney &lt;= 0{</pre><pre>resultLabel.text = “Game Over!”</pre><pre>}</pre><blockquote><strong><em>按Reset之後的顯示結果</em></strong></blockquote><pre><strong>@IBAction</strong> <strong>func</strong> reset(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>playerMoney = 10000</pre><pre>playerMoneyLabel.text = &quot;\(playerMoney)&quot;</pre><pre>bet = 1000</pre><pre>moneyLabel.text = &quot;\(bet)&quot;</pre><pre>computerCardLabel.text = &quot;&quot;</pre><pre>playerCardLabel.text = &quot;&quot;</pre><pre>resultLabel.text = &quot;&quot;</pre><pre>moneyStepper.value = 1</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*Y6USEoId7D-eJitdUiVcLQ.gif" /></figure><h3><strong>GitHub</strong></h3><p><a href="https://github.com/ting3242006/BigSmall">https://github.com/ting3242006/BigSmall</a></p><h3><strong>參考資料</strong></h3><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/48-%E9%AA%B0%E5%AD%90%E8%BD%89%E8%BD%89%E8%BD%89%E5%92%8C%E9%AA%B0%E5%AD%90%E5%90%B9%E7%89%9B-69368b4e8382">#48 骰子轉轉轉 &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/swift%E5%85%A5%E9%96%80%E7%AC%AC50%E5%A4%A9-%E5%8D%81%E8%B3%AD%E4%B9%9D%E8%BC%B8%E4%B9%8B%E9%AA%B0%E5%AD%90%E7%8C%9C%E5%A4%A7%E5%B0%8F-fd1c4909adc4">Swift入門第014天-十賭九輸之骰子猜大小</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/48-%E9%AA%B0%E5%AD%90%E8%BD%89%E8%BD%89%E8%BD%89-%E6%AF%94%E5%A4%A7%E5%B0%8F-%E9%AA%B0%E5%AD%90%E5%90%B9%E7%89%9B-ec8ce9e5c307">#35 骰子轉轉轉，比大小，骰子吹牛</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/46-%E7%B5%A6%E9%96%8B%E5%8F%B8%E4%BE%86%E7%BD%90%E5%95%A4%E9%85%92-%E6%AF%94%E5%A4%A7%E5%B0%8F%E9%AA%B0%E5%AD%90%E9%81%8A%E6%88%B2-5451ec8a0e0">#46 給開司來罐啤酒！比大小骰子遊戲</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9191fab927e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-22-%E6%92%B2%E5%85%8B%E7%89%8C%E6%AF%94%E5%A4%A7%E5%B0%8F%E9%81%8A%E6%88%B2-9191fab927e0">Swift|22 撲克牌比大小遊戲</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[Swift|21 幫波妞換衣服-調色大師]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-21-%E5%B9%AB%E6%B3%A2%E5%A6%9E%E6%8F%9B%E8%A1%A3%E6%9C%8D-%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-2bf2ca904a36?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bf2ca904a36</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Mon, 30 Aug 2021 16:26:30 GMT</pubDate>
            <atom:updated>2021-08-31T03:13:22.665Z</atom:updated>
            <content:encoded><![CDATA[<p>學習目的：@IBAction、@IBOutlet、Slider、random</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*CahVumqhOBeOCA9k2JroLQ.gif" /></figure><ol><li>先幫波妞的衣服去背</li></ol><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%A6%82%E4%BD%95%E7%94%A8-previe-app-%E9%A0%90%E8%A6%BD%E7%A8%8B%E5%BC%8F-%E5%8E%BB%E8%83%8C%E5%9C%96%E7%89%87-f44640424ba2">如何用 Preview App (預覽程式)去背圖片</a></p><p>2.我選了點點圖案當底層，原本波妞的衣服沒有點點圖案</p><p>3.加入slider拉@IBOutlet</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> ponyoImageView: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> redSlider: UISlider!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> greenSlider: UISlider!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> blueSlider: UISlider!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> alphaSlider: UISlider!</pre><p>4.再將slider拉@IBAction</p><pre><strong>@IBAction</strong> <strong>func</strong> changeColor(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>ponyoImageView.backgroundColor = UIColor(</pre><pre>red: CGFloat(redSlider.value),</pre><pre>green: CGFloat(greenSlider.value),</pre><pre>blue: CGFloat(blueSlider.value),</pre><pre>alpha: CGFloat(alphaSlider.value))</pre><pre>}</pre><blockquote>@IBAction做一樣的事，所以只要拉 1 個 IBAction</blockquote><blockquote>拉 image view &amp; slider 的 outlet，才能從程式存取 image view &amp; slider</blockquote><blockquote>有可能同一個元件同時拉 outlet和 action</blockquote><p>可以在 CGFloat( ) 傳入 Float 型別的東⻄，生出 CGFloat 的東⻄</p><p><a href="https://ting3242006.medium.com/swift-20-editor-placeholder-in-source-file-%E7%9A%84%E9%8C%AF%E8%AA%A4-85f61345be9a">Swift|20 Editor placeholder in source file 的錯誤</a></p><p>上面是在這次作業中遇到的問題，另外寫成一篇文章</p><p>5.加入隨機（亂數）功能</p><pre><strong>@IBAction</strong> <strong>func</strong> randomColor(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>redSlider.value = Float.random(in: 0...1)</pre><pre>greenSlider.value = Float.random(in: 0...1)</pre><pre>blueSlider.value = Float.random(in: 0...1)</pre><pre>alphaSlider.value = Float.random(in: 0.5...1)</pre><pre>ponyoImageView.backgroundColor = UIColor(red: CGFloat(redSlider.value), green: CGFloat(greenSlider.value), blue: CGFloat(blueSlider.value), alpha: CGFloat(alphaSlider.value))</pre><p>因為參數的型別是 CGFloat，所以要用 CGFloat.random</p><h3>參考文章</h3><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/%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-swift-ios-app-%E4%BD%9C%E6%A5%AD-a8ab4d968034">#13 調色大師</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/5-%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E5%BD%B1%E5%AD%90-%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-145dbd1f6f16">#5 彼得潘的影子 — 調色大師</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/%E8%A6%81%E8%AA%BF%E5%B9%BE%E6%AC%A1-%E9%9A%A8%E6%A9%9F-%E9%87%8D%E4%BE%86%E9%83%BD%E5%8F%AF%E4%BB%A5-%E6%81%90%E9%BE%8D%E7%9A%84%E5%B8%BD%E5%AD%90%E8%AA%BF%E8%89%B2%E9%80%B2%E9%9A%8E%E7%89%88-%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-app-3d68b6893f74">要調幾次、隨機、重來都可以！恐龍的帽子調色進階版─調色大師 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/%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-%E5%8A%A0%E4%B8%8A%E4%BA%82%E6%95%B8%E5%92%8C%E6%BC%B8%E5%B1%A4-wellpaper-girl-226f0e67edb0">調色大師 (加上亂數和漸層)-Wellpaper&amp;Girl</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/hw-9-1-%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-8203ca43b00">HW#9.1 調色大師</a></li></ul><h3>GitHub</h3><p><a href="https://github.com/ting3242006/changeColorApp">https://github.com/ting3242006/changeColorApp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bf2ca904a36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-21-%E5%B9%AB%E6%B3%A2%E5%A6%9E%E6%8F%9B%E8%A1%A3%E6%9C%8D-%E8%AA%BF%E8%89%B2%E5%A4%A7%E5%B8%AB-2bf2ca904a36">Swift|21 幫波妞換衣服-調色大師</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[Swift|20 Editor placeholder in source file 的錯誤]]></title>
            <link>https://ting3242006.medium.com/swift-20-editor-placeholder-in-source-file-%E7%9A%84%E9%8C%AF%E8%AA%A4-85f61345be9a?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/85f61345be9a</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Mon, 30 Aug 2021 11:58:37 GMT</pubDate>
            <atom:updated>2021-08-30T11:58:37.386Z</atom:updated>
            <content:encoded><![CDATA[<p>在做作業的時候，打完程式碼一直出現這樣的錯誤</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*dmndm6T587Md_u9OhIvZkQ.png" /></figure><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/xcode%E7%9A%84swift%E8%87%AA%E5%8B%95%E5%AE%8C%E6%88%90%E8%AE%8A%E5%BE%97%E6%9B%B4%E5%BC%B7%E5%A4%A7%E4%BA%86-87e0ed1adf67">有讀心術的 Xcode 自動完成(Autocomplete)</a></p><p>會一直覺得困惑是因為我是用自動完成去選擇的<br>出現錯誤的時候<br>覺得怪怪的地方是這段程式碼只有灰色，都沒有顏色<br>答案是要按<strong><em>Enter!</em></strong></p><p>如果程式碼內還有灰色長方形框框<br>表示我們還有地方<strong>沒有輸入資料</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%9C%A8-xcode-%E5%AF%AB%E7%A8%8B%E5%BC%8F%E6%99%82%E7%9A%84%E8%97%8D%E8%89%B2%E5%92%8C%E7%81%B0%E8%89%B2%E8%BC%B8%E5%85%A5%E6%A1%86-1c63182debf6">在 Xcode 寫程式時的長條輸入框</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*hbs9zZqwm-GcM-77qi0b5w.png" /></figure><p>但是當我打完確認沒有灰色長方形框框<br>還是一直出現錯誤訊息重開Xcode或project都沒有用<br>詢問彼得潘大大後<br>他建議我按<strong><em>cmd+b<br></em></strong>重新built一次<br>果然就恢復正常了！</p><p>重開Xcode或project不一定會重跑<br>下次遇到問題時可以先試試<strong><em>cmd+b</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85f61345be9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift|19 if條件練習]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-19-if%E6%A2%9D%E4%BB%B6%E7%B7%B4%E7%BF%92-14023cce1842?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/14023cce1842</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Tue, 24 Aug 2021 12:17:51 GMT</pubDate>
            <atom:updated>2021-08-24T14:18:19.935Z</atom:updated>
            <content:encoded><![CDATA[<p>用生活化例子來了解if的用法</p><p>if 放假{<br>約朋友去海邊()<br>釣魚()<br>吃海產()<br>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14023cce1842" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-19-if%E6%A2%9D%E4%BB%B6%E7%B7%B4%E7%BF%92-14023cce1842">Swift|19 if條件練習</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[Swift|18 運用 UIBezierPath 繪製蠟筆小新裡的小白]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-18-%E9%81%8B%E7%94%A8-uibezierpath-%E7%B9%AA%E8%A3%BD%E8%A0%9F%E7%AD%86%E5%B0%8F%E6%96%B0%E8%A3%A1%E7%9A%84%E5%B0%8F%E7%99%BD-b857c6fe7ec2?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/b857c6fe7ec2</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uibezierpath]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Sun, 15 Aug 2021 17:10:26 GMT</pubDate>
            <atom:updated>2021-08-16T06:05:02.418Z</atom:updated>
            <content:encoded><![CDATA[<p>運用UIBezierPath搭配CGAffineTransform來畫圖</p><p>使用到的語法有</p><ul><li>func move(to: CGPoint)起始點移動到指定位置</li><li>func addLine(to: CGPoint) 增加一條直線</li><li>func addArc(withCenter: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) 增加一個弧線（圓形）</li><li>func addCurve(to: CGPoint, controlPoint1: CGPoint, controlPoint2: CGPoint) 增加一條立方貝塞爾曲線</li><li>func addQuadCurve(to endPoint:CGPoint, controlPoint:CGPoint) 增加一條二次貝塞爾曲線</li><li>var cgPath: CGPath 路徑的核心圖形表示</li></ul><p>選擇自己要畫的圖片<br>可以上傳到這個網站裡查詢座標和顏色<br><a href="https://yangcha.github.io/iview/iview.html">https://yangcha.github.io/iview/iview.html</a></p><h3>成果</h3><p>除了畫小白以外<br>也用小新睡衣上的元素來練習畫三角形、圓形和正方形</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*4QVoZpTSQk9OS-K2EOdA8A.png" /></figure><h3>遇到的問題</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*EBMZeaH6cFFMewSvoirjXg.png" /></figure><p>原本是要將腮紅改成紅色<br>小白臉的線條也變成紅色了<br>想了好久還是想不出來<br>請教了彼得潘大神</p><p>原來是brush要產生新的 path<br>才不會跟原本的 path 混在一起<br>所以將腮紅設成path2</p><pre><strong>let</strong> path2 = UIBezierPath()</pre><pre>path2.move(to: CGPoint(x: 316, y: 191))</pre><pre>path2.addQuadCurve(to: CGPoint(x: 327, y: 208), controlPoint:CGPoint(x: 323, y: 202))</pre><pre>path2.move(to: CGPoint(x: 332, y: 187))</pre><pre>path2.addQuadCurve(to: CGPoint(x: 341, y: 212), controlPoint: CGPoint(x: 337, y: 199))</pre><pre>path2.move(to: CGPoint(x: 351, y: 202))</pre><pre>path2.addQuadCurve(to: CGPoint(x: 354, y: 213), controlPoint: CGPoint(x: 352, y: 208))<br></pre><pre><strong>let</strong> blush = CAShapeLayer()</pre><pre>blush.path = path2.cgPath</pre><pre>blush.fillColor = UIColor.clear.cgColor</pre><pre>blush.lineWidth = 4</pre><pre>blush.strokeColor = UIColor.red.cgColor</pre><pre>view.layer.addSublayer(blush)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*bm63B3njWwSFg0llhpwFDA.png" /></figure><p>還有一個問題是原本照著網站上的座標畫的小白右半耳會不見<br>所以必須要將他整隻位移<br>解決方法就是要新增一個UIView<br>讓全部的部分都可以一起移動</p><pre><strong>let</strong> baiMoveLeft = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))</pre><pre>baiMoveLeft.layer.addSublayer(face)</pre><pre>baiMoveLeft.layer.addSublayer(lefteye)</pre><pre>baiMoveLeft.layer.addSublayer(leftEar)</pre><pre>baiMoveLeft.layer.addSublayer(righteye)</pre><pre>baiMoveLeft.layer.addSublayer(rightEar)</pre><pre>baiMoveLeft.layer.addSublayer(nose)</pre><pre>baiMoveLeft.layer.addSublayer(body)</pre><pre>baiMoveLeft.layer.addSublayer(blush)</pre><pre>baiMoveLeft.transform = CGAffineTransform(translationX: -45, y: 150)</pre><pre>view.addSubview(baiMoveLeft)</pre><h3>心得</h3><p>畫圖這關讓我有點小卡關<br>一直不停的找文章來研究<br>但是慢慢研究＋動手開始做<br>漸漸出現成果<br>又過了一個小關卡的感覺啊！！！<br>但是有一些概念還是得弄清楚<br>不然很容易卡住<br>繼續努力吧～</p><h3>程式碼</h3><p><a href="https://github.com/ting3242006/DemoDraw">GitHub - ting3242006/DemoDraw</a></p><h3>參考資料</h3><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/%E4%BD%BF%E7%94%A8-swiftui-%E9%A0%90%E8%A6%BD-uibezierpath-%E7%9A%84%E7%B9%AA%E5%9C%96%E7%B5%90%E6%9E%9C-5d5b8e679287">使用 SwiftUI 預覽 UIBezierPath 的繪圖結果</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/%E9%81%8B%E7%94%A8-uibezierpath-%E7%B9%AA%E8%A3%BD%E5%8F%AF%E6%84%9B%E5%9C%96%E6%A1%88-%E6%AF%94%E6%96%B9%E9%9B%AA%E4%BA%BA-%E7%B1%B3%E5%A5%87-%E5%8F%AF%E6%84%9B%E5%8B%95%E7%89%A9-12d3a5ef1d6c">#52 運用 UIBezierPath 模仿繪製可愛圖案，比方 Swift &amp; Hello Kitty</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%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-cgaffinetransform-%E6%8E%A7%E5%88%B6%E5%85%83%E4%BB%B6%E7%B8%AE%E6%94%BE-%E4%BD%8D%E7%A7%BB-%E6%97%8B%E8%BD%89%E7%9A%84%E4%B8%89%E7%A8%AE%E6%96%B9%E6%B3%95-dca1abbf9590">利用 CGAffineTransform 控制元件縮放，位移，旋轉的三種方法</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/ios13-app-swift5-%E5%AF%A6%E4%BE%8B%E8%AA%AA%E6%98%8E-%E4%BD%BF%E7%94%A8-uibezierpath%E4%BE%86%E7%B9%AA%E8%A3%BD%E5%9C%96%E6%A1%88-cc192b3addc5">IOS13 APP『Swift5』實例說明 —使用 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/%E9%81%8B%E7%94%A8uibezierpath%E7%B9%AA%E8%A3%BD%E5%9C%96%E6%A1%88-%E6%98%A5%E4%B8%8A%E9%9A%86%E5%B0%8F%E8%8A%B1-2b5560f65c0f">運用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/%E9%81%8B%E7%94%A8-uibezierpath-%E7%B9%AA%E8%A3%BD%E5%8F%AF%E6%84%9B%E8%B2%93%E8%B2%93%E8%9F%B2%E5%92%96%E6%B3%A2-9187a4ea4804">運用 UIBezierPath 繪製可愛貓貓蟲咖波</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b857c6fe7ec2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-18-%E9%81%8B%E7%94%A8-uibezierpath-%E7%B9%AA%E8%A3%BD%E8%A0%9F%E7%AD%86%E5%B0%8F%E6%96%B0%E8%A3%A1%E7%9A%84%E5%B0%8F%E7%99%BD-b857c6fe7ec2">Swift|18 運用 UIBezierPath 繪製蠟筆小新裡的小白</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[Swift|17 做出告白機器人]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/swift-17-%E5%81%9A%E5%87%BA%E5%91%8A%E7%99%BD%E6%A9%9F%E5%99%A8%E4%BA%BA-fa9c938f2de6?source=rss-a07aa3bd2213------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9c938f2de6</guid>
            <category><![CDATA[avspeechsynthesizer]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yi Ting Sung]]></dc:creator>
            <pubDate>Sat, 14 Aug 2021 17:31:09 GMT</pubDate>
            <atom:updated>2021-08-15T02:40:46.206Z</atom:updated>
            <content:encoded><![CDATA[<p>今天是七夕情人節<br>用可愛的popcat來做出告白機器人～<br>學習使用 AVSpeechSynthesizer 講話</p><blockquote><em>第一 先用popcat印出歌詞</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-zKUF4Y2_S-G219fb2Ijw.png" /><figcaption>點popcat的圖案印出歌詞</figcaption></figure><blockquote><em>第二 用popcat來說話</em></blockquote><pre><strong>import</strong> UIKit</pre><pre><strong>import</strong> AVFoundation</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> loveTextField: UITextField!</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> speak(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre><strong>let</strong> speechUtterance = AVSpeechUtterance(string: loveTextField.text!)</pre><pre>speechUtterance.voice = AVSpeechSynthesisVoice(language: &quot;zh-TW&quot;)</pre><pre>speechUtterance.rate = 0.55 //加快語速</pre><pre><strong>let</strong> synthesizer = AVSpeechSynthesizer()</pre><pre>synthesizer.speak(speechUtterance)</pre><pre>}</pre><pre>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FeQGKyjCnUrg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeQGKyjCnUrg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FeQGKyjCnUrg%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/b17da757a640cfc6f3ebbc0ae1295cbe/href">https://medium.com/media/b17da757a640cfc6f3ebbc0ae1295cbe/href</a></iframe><p>希望下次可以更新成按了popcat嘴巴會動的版本</p><h4>Github:</h4><p><a href="https://github.com/ting3242006/SpeakingApp">https://github.com/ting3242006/SpeakingApp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9c938f2de6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/swift-17-%E5%81%9A%E5%87%BA%E5%91%8A%E7%99%BD%E6%A9%9F%E5%99%A8%E4%BA%BA-fa9c938f2de6">Swift|17 做出告白機器人</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>