<?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 Hsieh Hao-Yun on Medium]]></title>
        <description><![CDATA[Stories by Hsieh Hao-Yun on Medium]]></description>
        <link>https://medium.com/@haoyun0317?source=rss-ac9affddaa6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WJZvhZxXh7EqZK9i</url>
            <title>Stories by Hsieh Hao-Yun on Medium</title>
            <link>https://medium.com/@haoyun0317?source=rss-ac9affddaa6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 00:12:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haoyun0317/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[Apple Store 的 AirPods Pro 刻字]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/apple-store-%E7%9A%84-airpods-pro-%E5%88%BB%E5%AD%97-a23389b8e8ab?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a23389b8e8ab</guid>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Thu, 18 Mar 2021 06:38:01 GMT</pubDate>
            <atom:updated>2021-03-18T10:21:01.021Z</atom:updated>
            <content:encoded><![CDATA[<h4>@IBAction textField vevet Editing Changed, Custom Class</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FVEQBqY6SJY8&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVEQBqY6SJY8&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FVEQBqY6SJY8%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/b22c42cf32bc987a0c16840d1f037303/href">https://medium.com/media/b22c42cf32bc987a0c16840d1f037303/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*8wo8-Jq-F9-xojYi1zIeiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*Gdnq9ZMsRLEi8OuwJaMxRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*JmmxFiq8m6iVVIM_N17c2w.png" /><figcaption>左至右（圖一、圖二、圖三）</figcaption></figure><p>因為想做的完整一些，所以不只做圖三這一個畫面而已。</p><ul><li>圖一 navigation controller，add button拉線到第二個view controller</li><li>圖二 button 寫了cornerRadius, borderWidth, borderColor 讓button可以調整外框粗細，顏色，圓角</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c67540147128a72dd3a9a75e05c12e3b/href">https://medium.com/media/c67540147128a72dd3a9a75e05c12e3b/href</a></iframe><ul><li>圖三 因為需要打程式，所以要有一個自己的viewController，第一、cmd+N，第二、 選cocoa touch class，第三、 設定自己viewController的名稱，第四、 下面一行Subclass of: UIViewController，第五、 回到main.storyboard選到要寫程式的viewController，第六、選自己的Custom class</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbeAU-X9Uj9uCx036MmhVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buUAiDx8bXDKQ_rRMAPxYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PTmYESY6ap9l8CozhJHWA.png" /></figure><p>程式</p><p>這個在拉action的時候選擇UITextField這樣可以直接使用sender的值，同時要更改event成為 Editing Changed 這樣才有同樣的打字效果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*YIpEieS6aJzBofrzwVnf2Q.png" /></figure><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> label: UILabel!</pre><pre><strong>@IBAction</strong> <strong>func</strong> editChange(<strong>_</strong> sender: UITextField) {</pre><pre>    label.text = sender.text   </pre><pre>}</pre><p>參考</p><ul><li><a href="https://tsaenogard.pixnet.net/blog/post/96293854-swift-%E5%B0%87%E6%A1%86%E7%B7%9A%E5%8A%A0%E5%85%A5storyboard%E8%A8%AD%E5%AE%9A">swift 將UIButton框線加入storyboard設定 @ MasBlue釔銦錳藍 :: 痞客邦 ::</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/106-apple-store-%E7%9A%84-airpods-pro-%E5%88%BB%E5%AD%97-316e1f054ad1">#106 LINE 貼圖，AirTag，AirPods Pro 隨你填</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a23389b8e8ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/apple-store-%E7%9A%84-airpods-pro-%E5%88%BB%E5%AD%97-a23389b8e8ab">Apple Store 的 AirPods Pro 刻字</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[模擬 2020 WWDC 圖片]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%A8%A1%E6%93%AC-2020-wwdc-%E5%9C%96%E7%89%87-bff786445b4e?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bff786445b4e</guid>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Sat, 13 Mar 2021 08:59:37 GMT</pubDate>
            <atom:updated>2021-03-13T09:00:22.740Z</atom:updated>
            <content:encoded><![CDATA[<h4>複習UIBezierPath(), CAShapeLayer(), CGAffineTransform</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*22IAlEDnq6daPvmkjNiZrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBEx_n5ySX9XoC9Jg6s6RA.jpeg" /></figure><ul><li>Apple Logo 我直接用學長的Path(<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/43-%E5%BE%9E%E7%A8%8B%E5%BC%8F%E8%A3%BD%E4%BD%9C%E5%9C%8B%E6%97%97%E5%9C%96%E6%A1%88-fc3ebed11bbe">連結在這</a>)，省了非常多時間</li><li>MacbookView的俯視圖有使用layer.cornerRadius</li><li>WWDC跟2021使用UILabel貼上UIView上，再貼上macbookView</li><li>剩下的網上抓圖片，去背後貼上macbookView喬位置</li></ul><p>重點：</p><p>要使用CGAffineTransform的位移，放大縮小，旋轉的話，除非只用一種，不然程式要寫在一起，先寫旋轉，再寫位移，這樣是不行的</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*DFYvvEpNEulCdFdkw-YAeQ.png" /></figure><p>要打成一行</p><pre>CGAffineTransform.identity.translatedBy(x: 0, y: 0).scaledBy(x: 0, y: 0).rotated(by: .pi / 180)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bff786445b4e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%A8%A1%E6%93%AC-2020-wwdc-%E5%9C%96%E7%89%87-bff786445b4e">模擬 2020 WWDC 圖片</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[Storyboard電子書(不用寫code)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/storyboard%E9%9B%BB%E5%AD%90%E6%9B%B8-%E4%B8%8D%E7%94%A8%E5%AF%ABcode-2fe8c97d784d?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fe8c97d784d</guid>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 10:52:43 GMT</pubDate>
            <atom:updated>2021-03-13T13:33:21.318Z</atom:updated>
            <content:encoded><![CDATA[<h4>複習Tab Bar Controller/ Navigation Controller/ View Controller/ Table View Controller/ Scroll View</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjXM59bBHi-4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjXM59bBHi-4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjXM59bBHi-4%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/cc53dfa0ec1a745974a141ec86bd8891/href">https://medium.com/media/cc53dfa0ec1a745974a141ec86bd8891/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7d_3y0Q0CFAGYoq7HQKHag.png" /></figure><h4>Scroll View</h4><p>加入一個scrollView設定好可以顯示內容的大小，加入一個view，先放在外面，同樣也設定好所有內容的大小，這邊注意view會比scrollView還要大，這樣才能滑動。</p><p>設定contentSize Size，value有分水平滑動y=0，垂直滑動x=0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*ztnT4y6lXQYnoixxqEYAsw.png" /><figcaption>垂直滑動，x=0</figcaption></figure><h4>layer.cornerRadius</h4><p>蘋果的設計多是圓角，所以善用這個可以上imageView/ Button變圓角</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*GrdZtgRpNHfotQNf_M5x5g.png" /><figcaption>正圓形,value是長寬的一半</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*ntRoQOBaefXUCRvITNNoLA.png" /><figcaption>button也可以變圓角</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fe8c97d784d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/storyboard%E9%9B%BB%E5%AD%90%E6%9B%B8-%E4%B8%8D%E7%94%A8%E5%AF%ABcode-2fe8c97d784d">Storyboard電子書(不用寫code)</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[在viewDidLoad裡客制App畫面]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%9C%A8viewdidload%E8%A3%A1%E5%AE%A2%E5%88%B6app%E7%95%AB%E9%9D%A2-a10d02065902?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a10d02065902</guid>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Wed, 17 Feb 2021 08:31:03 GMT</pubDate>
            <atom:updated>2021-02-17T09:04:44.508Z</atom:updated>
            <content:encoded><![CDATA[<h4>直接用gif檔案做gif動畫, CAGradientLayer()製作漸層, CAEmitterCell()製作下雪場景</h4><h4>這次練習重點在新的gif檔案製作</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FY-J_2aUNUmM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DY-J_2aUNUmM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FY-J_2aUNUmM%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/b5641e2062eb6fb172c9a3c317c896f3/href">https://medium.com/media/b5641e2062eb6fb172c9a3c317c896f3/href</a></iframe><p>這次換個方式製作gif動畫，是ios13之後的新功能，直接把gif檔案拉進Assets裡面，然後打下面的程式碼。</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-cganimateimageaturlwithblock-%E6%92%AD%E6%94%BE-gif-4780071b835e">利用 CGAnimateImageDataWithBlock &amp; CGAnimateImageAtURLWithBlock 播放 gif</a></p><pre><strong>guard</strong> <strong>let</strong> data = NSDataAsset(name: &quot;animated-train-image-13&quot;)?.data</pre><pre><strong>else</strong> { <strong>return</strong> }</pre><pre><strong>var</strong> cfData = data <strong>as</strong> CFData</pre><pre>CGAnimateImageDataWithBlock(cfData, <strong>nil</strong>) { (<strong>_</strong>, cgImage, <strong>_</strong>) <strong>in</strong></pre><pre><strong>        self</strong>.imageView.image = UIImage(cgImage: cgImage)</pre><pre>}//第一個gif火車</pre><pre><strong>guard</strong> <strong>let</strong> data1 = NSDataAsset(name: &quot;animated-snow-image-33&quot;)?.data</pre><pre><strong>else</strong> { <strong>return</strong> }</pre><pre>cfData = data1 <strong>as</strong> CFData</pre><pre>CGAnimateImageDataWithBlock(cfData, <strong>nil</strong>) { (<strong>_</strong>, cgImage, <strong>_</strong>) <strong>in</strong></pre><pre><strong>        self</strong>.snowImageView.image = UIImage(cgImage: cgImage)</pre><pre>}//第二個gif山頂的小雪</pre><pre><strong>let</strong> gradientLayer = CAGradientLayer()</pre><pre>gradientLayer.frame = view.bounds</pre><pre>gradientLayer.colors = [UIColor.systemTeal.cgColor, UIColor.lightGray.cgColor]</pre><pre>gradientLayer.startPoint = CGPoint(x: 0, y: 0)</pre><pre>gradientLayer.endPoint = CGPoint(x: 1, y: 1)</pre><pre>view.layer.addSublayer(gradientLayer)</pre><pre>view.layer.insertSublayer(gradientLayer, at: 0)</pre><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%E6%95%99%E5%AE%A4/%E7%94%A8cagradientlayer%E8%A3%BD%E4%BD%9C%E6%BC%B8%E5%B1%A4-%E7%94%A8viewdidload%E8%A3%BD%E4%BD%9Capp%E7%95%AB%E9%9D%A2-abc2298254d0">之前有寫過，請參考</a>。</p><pre><strong>let</strong> snowEmitterCell = CAEmitterCell()</pre><pre>snowEmitterCell.contents = UIImage(named: &quot;snow&quot;)?.cgImage</pre><pre>snowEmitterCell.birthRate = 10</pre><pre>snowEmitterCell.lifetime = 60</pre><pre>snowEmitterCell.scaleRange = 0.5</pre><pre>snowEmitterCell.velocity = 50</pre><pre>snowEmitterCell.yAcceleration = 7</pre><pre>snowEmitterCell.scale = 0.9</pre><pre><strong>let</strong> snowEmitterLayer = CAEmitterLayer()</pre><pre>snowEmitterLayer.emitterPosition = CGPoint(x: view.bounds.width / 2, y: -50)</pre><pre>snowEmitterLayer.emitterSize = CGSize(width: view.bounds.width, height: 0)</pre><pre>snowEmitterLayer.emitterShape = .line</pre><pre>snowEmitterLayer.emitterCells = [snowEmitterCell]</pre><pre>view.layer.addSublayer(snowEmitterLayer)</pre><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%E6%95%99%E5%AE%A4/%E5%88%A9%E7%94%A8-caemitterlayer-%E8%A3%BD%E4%BD%9Cballoon%E9%A3%9B%E4%B8%8A%E5%A4%A9%E7%A9%BA%E7%9A%84%E5%8B%95%E7%95%AB-3ca560975997">之前有寫過，在這邊。</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%88%A9%E7%94%A8-spritekit-particle-file-%E8%A3%BD%E9%80%A0%E4%B8%8B%E9%9B%AA%E7%9A%84%E7%B2%92%E5%AD%90%E6%95%88%E6%9E%9C-cd07303a10af">利用 SpriteKit Particle File 製造下雪的粒子效果</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-caemitterlayer-%E8%A3%BD%E4%BD%9C-xmas-%E7%9A%84%E4%B8%8B%E9%9B%AA%E5%8B%95%E7%95%AB-ee5f7cae621e">利用 CAEmitterLayer 製作 Xmas 的下雪動畫</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-uiimageview-%E6%92%AD%E6%94%BE%E5%8B%95%E7%95%AB-f48959b6882a">利用 UIImageView 實現多張圖片連續播放的動畫</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*fbndTJBzF4WORonVtYFC_Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a10d02065902" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%9C%A8viewdidload%E8%A3%A1%E5%AE%A2%E5%88%B6app%E7%95%AB%E9%9D%A2-a10d02065902">在viewDidLoad裡客制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[Cards比大小(不含花色)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/cards%E6%AF%94%E5%A4%A7%E5%B0%8F-%E4%B8%8D%E5%90%AB%E8%8A%B1%E8%89%B2-7b0751ce3bb4?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b0751ce3bb4</guid>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Fri, 05 Feb 2021 05:46:17 GMT</pubDate>
            <atom:updated>2021-02-05T14:03:04.638Z</atom:updated>
            <content:encoded><![CDATA[<h4>nested loop產生52張牌, if else換算AJQK</h4><p>內文有求救，各位空閑之餘，幫幫忙(已解決感謝彼得潘)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*2w5YsGM99yI9LRjb_OfIPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*Zyl460gAkjhhgSGVtn1PgQ.png" /></figure><h4>如何產生52張牌</h4><pre>for rank in ranks {<br>    for suit in suits {<br>        let card = Card()<br>        card.rank = rank<br>        card.suit = suit<br>        cards.append(card)<br>    }<br>}<br>//ranks先就是數字Ａ先<br>//suits先就是花色梅花先</pre><h4>全部程式</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f79f8a3962383601c117ab2b871383d7/href">https://medium.com/media/f79f8a3962383601c117ab2b871383d7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9ku8uCK64JvSUge1UVqbg.png" /><figcaption>就是那個k錯了，大小寫沒注意到</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c91I3jOYSKhfusExBPOvnw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b0751ce3bb4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/cards%E6%AF%94%E5%A4%A7%E5%B0%8F-%E4%B8%8D%E5%90%AB%E8%8A%B1%E8%89%B2-7b0751ce3bb4">Cards比大小(不含花色)</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%88%A9%E7%94%A8-uibezierpath-%E5%AF%A6%E7%8F%BE-9364bf22fd1?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9364bf22fd1</guid>
            <category><![CDATA[swift-playgrounds]]></category>
            <category><![CDATA[uibezierpath]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Wed, 03 Feb 2021 06:45:01 GMT</pubDate>
            <atom:updated>2021-02-03T10:17:07.543Z</atom:updated>
            <content:encoded><![CDATA[<h4>圓環進度條, 甜甜圈圖表</h4><h4>圓環進度條(circular progress ring)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*0MUy1jBS5BfhT42W3Hn61w.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a69bb93300c4633936523e147ebd3dcb/href">https://medium.com/media/a69bb93300c4633936523e147ebd3dcb/href</a></iframe><p>fillColor是指填充色，通常我們只要外圈的進度條，所以 .clear</p><p><a href="https://developer.apple.com/documentation/quartzcore/cashapelayer/1522248-fillcolor">Apple Developer Documentation</a></p><h4>甜甜圈圖表(donut chart)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*e8-B9u5VGai-RhXUv6FU_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*qjKXfOFswAmw1cotT-NmXw.png" /><figcaption>radius:lineWidth(左上100:50, 右上50:50)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*stYpMTnaGGO9zcmnAFMhkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*SpdX_WQ3KIovGHfXytfJSQ.png" /><figcaption>radius:lineWidth(左下26:50, 右下25:50)</figcaption></figure><h4>說明radius跟lineWidth的關係：</h4><p>由上圖可知道數值不是直接的長度關係，而是兩者間的比例關係，所以radius不可以小於lineWidth的一半，不然直接變成圓餅圖了</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a55a49e5f51a388b3a53dd00adf5f45/href">https://medium.com/media/5a55a49e5f51a388b3a53dd00adf5f45/href</a></iframe><p>甜甜圈圖表標上文字（這裡我沒理解，之後再補上）</p><pre>func createLabel(percentage: CGFloat, startDegree: CGFloat) -&gt; UILabel {<br><strong>    let textCenterDegree = startDegree + 360 * percentage / 2 / 100<br>    let textPath = UIBezierPath(arcCenter: center, radius: radius, startAngle: aDegree * textCenterDegree, endAngle: aDegree * textCenterDegree, clockwise: true)</strong><br>    let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30))<br>    label.backgroundColor = UIColor.yellow<br>    label.font = UIFont.systemFont(ofSize: 8)<br>    label.text = &quot;\(percentage)%&quot;<br>    label.sizeToFit()<br>    label.center = textPath.currentPoint<br>    return label<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9364bf22fd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%88%A9%E7%94%A8-uibezierpath-%E5%AF%A6%E7%8F%BE-9364bf22fd1">利用 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[playgroundBook, while關卡]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/playgroundbook-while%E9%97%9C%E5%8D%A1-8ef6961c3c33?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef6961c3c33</guid>
            <category><![CDATA[while-loop]]></category>
            <category><![CDATA[swift-playgrounds]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Sat, 30 Jan 2021 07:47:53 GMT</pubDate>
            <atom:updated>2021-01-30T14:11:07.626Z</atom:updated>
            <content:encoded><![CDATA[<h4>while loop, if else, for loop</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pysEp8uIKb1bpF8IVgHWlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOon-nf36uki3gXSKxxPjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4KDbFfuqblWLU5ckeTh3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQTmyHYTE0KrqJ82IeKU8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T2DiRpRVKmKLUbeM0C6c_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*as_ayw8vDlgOrCIO-k87Gg.png" /></figure><pre>func firstLine() {</pre><pre>    while !isBlocked {</pre><pre>        if isOnClosedSwitch {</pre><pre>            toggleSwitch()</pre><pre>            moveForward()</pre><pre>        }else if isOnOpenSwitch {</pre><pre>            moveForward()</pre><pre>        }</pre><pre>    }</pre><pre>}</pre><pre>func secondLine() {</pre><pre>    while isOnGem {</pre><pre>        collectGem()</pre><pre>        moveForward()</pre><pre>    }</pre><pre>}</pre><pre>func right() {</pre><pre>    turnRight()</pre><pre>    moveForward()</pre><pre>    turnRight()</pre><pre>    moveForward()</pre><pre>}</pre><pre>func left() {</pre><pre>    turnLeft()</pre><pre>    moveForward()</pre><pre>    turnLeft()</pre><pre>    moveForward()</pre><pre>}</pre><pre>moveForward()</pre><pre>firstLine()</pre><pre>right()</pre><pre>secondLine()</pre><pre>left()</pre><pre>firstLine()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmJv__hoix2Rzn0MGOSomA.png" /></figure><pre>while !isBlocked {<br>    <br>    while !isOnGem {</pre><pre>        moveForward()<br>        //isOnGem迴圈</pre><pre>    }<br>    <br>    collectGem()<br>    turnLeft()<br>    //isBlocked迴圈</pre><pre>  }</pre><pre>// !isBlocked多了!判斷Ｔ或Ｆ會相反，這邊false進入下個判斷!isOnGem直到true<br>// 回到isBlocked的迴圈，執行collectGem and turnLeft<br>// 然後又從頭開始</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2PRSYNSwQPV0cN716h62A.png" /></figure><pre>!isBlocked -&gt; false, moveForward() 只能直走不能右轉<br>!isBlocked -&gt; true, isBlockedRight</pre><pre>isBlockedRight -&gt; true, !isBlocked<br>isBlockedRight -&gt; false, turnRight(), moveForward()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-PTwfqvgQuJB2qZhCHJihw.png" /></figure><pre>第九關了，知道直走就是要!isBlocked -&gt; false, moveForward()</pre><pre>這關有switch跟gem，可以用if。(不過這邊為何可以不用else?)</pre><h4>心得</h4><p>這遊戲設計的很用心，過程中教你觀念，讓你思考(就是沒給答案的意思)，不過想想，程式設計本來就沒有標準答案，只要能達到目標都行。</p><p>善用逐格播放，可以知到迴圈到底怎麼跑的。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef6961c3c33" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/playgroundbook-while%E9%97%9C%E5%8D%A1-8ef6961c3c33">playgroundBook, while關卡</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[card在playground上練習，如何生成52張撲克牌]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/card%E5%9C%A8playground%E4%B8%8A%E7%B7%B4%E7%BF%92-%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%9052%E5%BC%B5%E6%92%B2%E5%85%8B%E7%89%8C-a51f72cb57d6?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a51f72cb57d6</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[彼得潘ios作業]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 07:21:12 GMT</pubDate>
            <atom:updated>2021-01-27T14:39:35.471Z</atom:updated>
            <content:encoded><![CDATA[<h4>array, class Card, for loop, nested loop</h4><p>首先撲克牌有分花色suits跟大小ranks，那我們就來設花色與大小的常數，因為數量不是單一，所以我們採用集合類型array</p><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><p>第二我們對撲克牌進行分類class，屬性有suit跟rank</p><pre><strong>class</strong> Card {</pre><pre><strong>    var</strong> suit = &quot;&quot;</pre><pre><strong>    var</strong> rank = &quot;&quot;</pre><pre>}</pre><h4>一張一張產生</h4><pre><strong>var</strong> cards = [Card]()<br>//宣告變數cards = [Card空的]</pre><pre><strong>let</strong> card1 = Card()<br>//宣告常數card1 = suit&quot;&quot; rank&quot;&quot;</pre><pre>card1.suit = suits[0]<br>//card1的suit = suit &quot;♣️&quot;</pre><pre>card1.rank = ranks[0]<br>//card1的rank = rank &quot;A&quot;</pre><pre>cards.append(card1)<br>// 空的cards 加上 card1</pre><pre><strong>let</strong> card2 = Card()</pre><pre>card2.suit = suits[0]</pre><pre>card2.rank = ranks[1]</pre><pre>cards.append(card2)</pre><pre>//接著這樣做52次</pre><h4>for loop 迴圈產生</h4><pre><strong>var</strong> cards = [Card]()</pre><pre><strong>for</strong> i <strong>in</strong> 0...51 {</pre><pre><strong>let</strong> suitIndex = i / 13<br>//0~12 /13 = 0<br>//13~25 / 13 = 1<br>//26~38 / 13 = 2<br>//39~51 / 13 = 3<br>//這樣分剛好4種花色</pre><pre><strong>let</strong> rankIndex = i % 13<br>//求餘數<br>// 0/13餘0<br>// 1/13餘1<br>// 2/13餘2<br>// 以此類推</pre><pre><strong>let</strong> card = Card()</pre><pre>card.suit = suits[suitIndex]</pre><pre>card.rank = ranks[rankIndex]</pre><pre>cards.append(card)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*gCct84dX6TZ_H7Dzenw3CA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*r0meHsUf7jNgjoF7TnTcaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/124/1*qWUHrMgcbLHQCd8spas35Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*wXRTHEV1gfk03631mqcotg.png" /><figcaption>印出suitIndex, rankIndex方便理解</figcaption></figure><h4>nested loop 巢狀迴圈產生</h4><pre>var cards = [Card]()</pre><pre>for suit in suits {<br>    for rank in ranks {<br>        let card = Card()<br>        card.suit = suit<br>        card.rank = rank<br>        cards.append(card)<br>    }<br>}<br>//花色在前，產生同花色A to K，再進行回圈<br>//反之數字在前，產生同數字不同花色，四個Ａ不同花色，四個2不同花色，以此類推</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*GA4LF6MqaNBseqk5VROfmg.png" /><figcaption>for rank in ranks { for suit in suits {</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a51f72cb57d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/card%E5%9C%A8playground%E4%B8%8A%E7%B7%B4%E7%BF%92-%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%9052%E5%BC%B5%E6%92%B2%E5%85%8B%E7%89%8C-a51f72cb57d6">card在playground上練習，如何生成52張撲克牌</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[將 SVG 變成 UIBezierPath 再利用UIBezierPath 繪製]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%B0%87-svg-%E8%AE%8A%E6%88%90-uibezierpath-%E5%86%8D%E5%88%A9%E7%94%A8uibezierpath-%E7%B9%AA%E8%A3%BD-50ae9998584e?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/50ae9998584e</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[uibezierpath]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 07:36:15 GMT</pubDate>
            <atom:updated>2021-01-24T11:38:37.991Z</atom:updated>
            <content:encoded><![CDATA[<h4>path.addQuadCurve單個控制點, path.addCurve雙控制點</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*tgalIszd6AkPTW_kVjbSWQ.png" /></figure><p>之前就做過一次轉換svg但是只能簡單的圖形，這次來挑戰複雜一點的</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%E6%95%99%E5%AE%A4/%E6%8A%8Asvg%E5%9C%96%E7%89%87%E8%BD%89%E6%8F%9B%E6%88%90uibezierpath-a4b509f9ad9c">把SVG圖片轉換成UIBezierPath</a></p><p>怎麼轉換這裡就不多講，文末都會附上參考，這邊主要講之前為什麼沒法做複雜一些的圖，轉換完成要先找到 path.move跟path.close() ，這樣是一組layer，之後每一組都要自成一組layer，基本上就能成功</p><pre>path.move(to: CGPoint(x: 59, y: 65.2))<br>//start</pre><pre>path.addLine(to: CGPoint(x: 80.7, y: 101.1))</pre><pre>path.addLine(to: CGPoint(x: 67.4, y: 101.1))</pre><pre>path.addCurve(to: CGPoint(x: 52.9, y: 75.6), controlPoint1: CGPoint(x: 66.7, y: 90.5), controlPoint2: CGPoint(x: 61.1, y: 81.2))</pre><pre>path.addLine(to: CGPoint(x: 59, y: 65.2))</pre><pre>path.close()<br>//end</pre><pre><strong>let</strong> twoLayer = CAShapeLayer()</pre><pre>twoLayer.path = path.cgPath</pre><pre>twoLayer.strokeColor = UIColor.cyan.cgColor</pre><pre>twoLayer.fillColor = UIColor.clear.cgColor</pre><pre>twoLayer.lineWidth = 1</pre><pre>view.layer.addSublayer(twoLayer)</pre><h4>順便理解一下UIBezierPath()</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izcyGkWi1KCqlWaIeSNRcg.png" /></figure><pre>//直線我就跳過直線path.addLine</pre><pre>path.move(to: CGPoint(x: 0, y: 400))<br>//上面那條起始點</pre><pre>path.addQuadCurve(to: CGPoint(x: 400, y: 400), controlPoint: (CGPoint(x: 200, y: 300)))<br>//上面那條終點(400, 400)<br>//controlPoint(x:放在400的一半200位置, y:放在300位置）所以會在中間向上彎曲</pre><pre><br>path.move(to: CGPoint(x: 0, y: 600))<br>//第二條起點</pre><pre>path.addCurve(to: CGPoint(x: 400, y: 600), controlPoint1: CGPoint(x: 100, y: 500), controlPoint2: CGPoint(x: 300, y: 700))<br>//第二條終點(長度一樣400,高度落在600)<br>//第一個控制點(x:100,y:500),y在600位置上方，所以是x在100位置 向上彎曲<br>//第二個控制點(x:300,y:700),y在600位置下方，所以是x在300位置 向下彎曲</pre><p>下次學會動畫再更新一篇</p><blockquote>參考</blockquote><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%B0%87-svg-%E8%AE%8A%E6%88%90-uibezierpath-c9a6cd5b69ba">將 SVG 變成 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%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></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50ae9998584e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%B0%87-svg-%E8%AE%8A%E6%88%90-uibezierpath-%E5%86%8D%E5%88%A9%E7%94%A8uibezierpath-%E7%B9%AA%E8%A3%BD-50ae9998584e">將 SVG 變成 UIBezierPath 再利用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[利用 UIBezierPath 設計特別形狀的圖片]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%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-23a05ad4703e?source=rss-ac9affddaa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/23a05ad4703e</guid>
            <category><![CDATA[uibezierpath]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Hsieh Hao-Yun]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 09:34:40 GMT</pubDate>
            <atom:updated>2021-01-23T15:12:12.068Z</atom:updated>
            <content:encoded><![CDATA[<h4>Cocoa Touch Class搭配UIBezierPath，可以讓每張圖片都擁有需要的形狀</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*BGBuPdbWSMF5btt-LDIfAw.png" /><figcaption>上下兩張分別為兩組class</figcaption></figure><ol><li>首先 ⌘+N</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdoKJFmmTnl4dV5IyNdn8w.png" /></figure><p>2. Subclass 要選UIImageView</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ib6qdi80KRAaVJ7GlcO5sA.png" /></figure><p>3. 選則imageView, 然後右上Custom Classe改成剛剛設定的名稱，你所選定的imageView會套用成新的Class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2bLM_z7eoLfaoWf7fwPW_Q.png" /></figure><p>接下來就是代碼：</p><pre><strong>class</strong> testImageView: UIImageView {</pre><pre><strong>    override</strong> <strong>func</strong> layoutSubviews() {</pre><pre><strong>        super</strong>.layoutSubviews()<br>        //上面layoutSubviews是固定的，文末會附上參考</pre><pre><strong>        let</strong> path = UIBezierPath()<br>        //宣告常數path 為 UIBezierPath()<br>        //目的在使用它的功能</pre><pre>        path.move(to: CGPoint(x: 200, y: 30))<br>        //起始點path.move(to: CGPoint.zero) == <br>        //path.move(to: CGPoint(x: 0, y: 0)</pre><pre>        path.addLine(to: CGPoint(x: 400, y: 80))<br>        //第二個座標點</pre><pre>        path.addLine(to: CGPoint(x: bounds.width, y: 200))<br>        //第三個座標點 x: bounds.width 邊界.寬度, y: 200</pre><pre>        path.addLine(to: CGPoint(x: 0, y: bounds.height))<br>        //第四個座標點 x: 0, y: 邊界.高度</pre><pre>        path.close()<br>        //colse 最後一個座標點會連回起始點</pre><pre><strong>        let</strong> shapeLayer = CAShapeLayer()<br>        // 宣告常數shapeLayer 為 CAShapeLayer()<br>        // 目的在使用它的功能</pre><pre>        shapeLayer.path = path.cgPath<br>        // 使用path 並轉換成cgPath</pre><pre>        layer.mask = shapeLayer<br>        // 設定mask</pre><pre>    }</pre><pre>}</pre><h4>參考：</h4><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://developer.apple.com/documentation/uikit/uibezierpath/1624342-cgpath">Apple Developer Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23a05ad4703e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%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-23a05ad4703e">利用 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>
    </channel>
</rss>