<?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 Henry Huang on Medium]]></title>
        <description><![CDATA[Stories by Henry Huang on Medium]]></description>
        <link>https://medium.com/@dafu1231?source=rss-fa6d4ca6ffa3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YoKYt4aE4ujPJpAem8Z-_w@2x.jpeg</url>
            <title>Stories by Henry Huang on Medium</title>
            <link>https://medium.com/@dafu1231?source=rss-fa6d4ca6ffa3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:23:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dafu1231/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[我為什麼做了「鑫算機」]]></title>
            <link>https://dafu1231.medium.com/%E6%88%91%E7%82%BA%E4%BB%80%E9%BA%BC%E5%81%9A%E4%BA%86-%E9%91%AB%E7%AE%97%E6%A9%9F-86d5a9eb945f?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/86d5a9eb945f</guid>
            <category><![CDATA[定期定額]]></category>
            <category><![CDATA[side-project]]></category>
            <category><![CDATA[理財]]></category>
            <category><![CDATA[股票]]></category>
            <category><![CDATA[etf]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Thu, 12 Nov 2026 15:06:19 GMT</pubDate>
            <atom:updated>2026-11-12T15:06:19.631Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="鑫算機首頁，輸入股票代號查詢買進到今天的報酬" src="https://cdn-images-1.medium.com/max/1024/1*_hIQuIhl3nbmUzSgeF0RXw.png" /></figure><p>開始投資之後，腦袋常常會冒出一些問題:</p><ul><li>那檔股票如果當初買了，現在會是多少?</li><li>定期定額選幾號扣款，有差嗎?</li><li>房貸寬限期結束，每個月要多繳多少?</li></ul><p>上網找答案，找是找得到，但我常常不知道那個數字到底對不對。</p><p>既然自己會寫程式，現在又有 AI 幫忙，就乾脆自己做一個來算。</p><h4>做了才發現，沒那麼簡單</h4><p>一開始我以為很簡單：買進價跟現在的價格一減就好了。</p><p>結果做下去才發現一堆問題:</p><ul><li>股票分割了怎麼算?(0050 去年就一拆四)</li><li>這幾年領到的股利要不要算進去?</li><li>配股、減資之後，股數變了怎麼辦?</li></ul><p>還有好多細節，一個一個踩過才知道。所以每個計算機上線前，我都會另外算一組答案來對照，對上了才上線。</p><h4>鑫算機能算什麼</h4><p>現在有 20 幾個計算機，免費、不用註冊，大概分成這幾類:</p><ul><li><strong>股票報酬</strong>:<a href="https://fortunecalculator.com/calc/lump-sum">單筆買進</a>、<a href="https://fortunecalculator.com/calc/dca">定期定額試算</a>、<a href="https://fortunecalculator.com/calc/compare">兩檔比較</a>、<a href="https://fortunecalculator.com/calc/compound">複利計算機</a>、<a href="https://fortunecalculator.com/calc/annualized-return">年化報酬率</a></li><li><strong>存股配息</strong>:<a href="https://fortunecalculator.com/calc/monthly-dividend">存股月領</a>、<a href="https://fortunecalculator.com/calc/dividend-yield">殖利率</a>、<a href="https://fortunecalculator.com/calc/dividend-fill">填息天數</a></li><li><strong>費用和稅</strong>:<a href="https://fortunecalculator.com/calc/fee">股票手續費</a>、<a href="https://fortunecalculator.com/calc/dividend-tax">股利要繳多少稅</a></li><li><strong>貸款</strong>:<a href="https://fortunecalculator.com/calc/mortgage">房貸</a>、<a href="https://fortunecalculator.com/calc/personal-loan">信貸試算</a>、<a href="https://fortunecalculator.com/calc/car-loan">車貸試算</a>、<a href="https://fortunecalculator.com/calc/prepayment">提前還款</a></li></ul><figure><img alt="定期定額試算，0050 從 2016 年每月投 5,000 元到今天的結果" src="https://cdn-images-1.medium.com/max/1024/1*fg5n_Npfw02iGLz-FvYXdQ.png" /></figure><p>每檔股票也有自己的頁面，可以看歷年配了多少股利、以前最多跌過多少、花多久才漲回來，例如 <a href="https://fortunecalculator.com/stock/0050">0050</a>。</p><figure><img alt="0050 歷年配息、殖利率與歷史最大跌幅" src="https://cdn-images-1.medium.com/max/1024/1*M7W1OM2QLknDErYuU01UPw.png" /></figure><h4>它不做的事</h4><p>鑫算機只算過去發生的事，不預測未來，也不會告訴你該買哪一檔。我不是財務顧問，能做的就是把算法公開，讓你知道每個數字是怎麼來的。</p><h4>最後</h4><p>如果你也常常冒出「早知道……」的問題，歡迎來算算看:</p><p>👉 <a href="https://fortunecalculator.com/">https://fortunecalculator.com</a></p><p>我另外還做了一個比較輕鬆的網站「不算不知道」,把生活裡的數字換算成有感的結果:</p><p>👉 <a href="https://turnsoutcalculator.com/">https://turnsoutcalculator.com</a></p><p>有算錯的地方，或想要什麼計算機，歡迎跟我說。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86d5a9eb945f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NSLayoutConstraint Programming]]></title>
            <link>https://dafu1231.medium.com/nslayoutconstraint-programming-f1634f22eb7b?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1634f22eb7b</guid>
            <category><![CDATA[nslayoutconstraint]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[henry]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 05:15:07 GMT</pubDate>
            <atom:updated>2021-12-31T05:21:31.459Z</atom:updated>
            <content:encoded><![CDATA[<p>在iOS裡用storyboard建立UI和拉layoutConstraint是很方便、易學及快速的，但純程式碼建立UI也是很多人會選擇的方式，畢竟Xcode的storyboard速度實在有點慢。</p><p>用程式碼設定LayoutConstraint，要建立這樣的畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*oqeCqfIn0XsjI32ClDgqCA.png" /></figure><p>這樣簡單的畫面就要這麼多行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8ZQFyyirfxXKhp7_F4QYQ.png" /></figure><p>所以可以幫UIView建立一個Extention，來設定LayoutConstraint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-G2lRGuE4li069K7_0Il3w.png" /></figure><pre>extension UIView {</pre><pre>  func setConstraint(topA: NSLayoutYAxisAnchor, topConstraint: CGFloat?, leadingA: NSLayoutXAxisAnchor, leadingConstraint: CGFloat?, bottomA:NSLayoutYAxisAnchor, bottomConstraint: CGFloat?, trailingA: NSLayoutXAxisAnchor, trailingConstraint: CGFloat?) {</pre><pre>    self.translatesAutoresizingMaskIntoConstraints = false</pre><pre>    if topConstraint != nil {</pre><pre>      self.topAnchor.constraint(equalTo: topA, constant:     topConstraint!).isActive = true</pre><pre>    }</pre><pre>    if leadingConstraint != nil {</pre><pre>      self.leadingAnchor.constraint(equalTo: leadingA, constant: leadingConstraint!).isActive = true</pre><pre>    }</pre><pre>    if bottomConstraint != nil {</pre><pre>      self.bottomAnchor.constraint(equalTo: bottomA, constant: -bottomConstraint!).isActive = true</pre><pre>    }</pre><pre>    if trailingConstraint != nil {</pre><pre>      self.trailingAnchor.constraint(equalTo: trailingA, constant: - trailingConstraint!).isActive = true</pre><pre>    }</pre><pre>  }</pre><pre>}</pre><p>這樣要在建立一個View設定LayoutConstraint就輕鬆多囉!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MgS0ttgl4Rr4_tTe4jfuAg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*mJw2HSuShU5gvhZvYeBK9w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1634f22eb7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IBSegueAction from iOS13]]></title>
            <link>https://dafu1231.medium.com/ibsegueaction-from-ios13-c5aeb1f6d298?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5aeb1f6d298</guid>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[ibsegueaction]]></category>
            <category><![CDATA[switf]]></category>
            <category><![CDATA[pass-value]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Sun, 28 Nov 2021 15:54:23 GMT</pubDate>
            <atom:updated>2021-11-28T15:54:23.788Z</atom:updated>
            <content:encoded><![CDATA[<p>突然發現從iOS13 開始引入的新的傳值方式都沒有使用過，看起來也滿不錯的，所以也來嘗試看看。</p><p>首先是viewController的設置，因為要傳值，當然就會有兩個，配置如下，</p><p>OneViewController有兩個輸入欄TextField，輸入要傳到下一頁的值，及一個Button，開啟下一頁。</p><p>TwoViewControoler，有兩個Label，用來顯示接收到的值。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PFEf2vVmK0T1vfIQ-0So9w.png" /></figure><p>接下來直接從Button 連接到TwoViewController，並選show</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaYg5_YTjln8nMRM4aTESg.png" /></figure><p>然後選擇那個segue，並連接到TwoViewController，就會看到要建立<strong>本次的重點：IBSegueAction</strong>囉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqArHp3YVhr3f8f9Uuy7fg.png" /></figure><p>將要建立的<strong>IBSegueAction</strong>取個名字</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5QlgwfZJDbj9PA3Z5_dQw.png" /></figure><p>就會自動建立預設的程式碼，暫時先不管他</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRhbEUdCspK8S6D9oVwxXA.png" /></figure><p>接下來我想先準備好一個struct，用來當做要OneViewController傳入及TwoViewController接收的屬性</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*53olRE1EWfczMO19zndgOA.png" /></figure><p>接著到TwoViewController，開始進行準備接收的準備囉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rX6DuMyboBGD0m_oGJvsgA.png" /></figure><p>最後回到OneViewController，修改<strong>IBSegueAction func toNext(_ coder) -&gt; TwoViewController?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PipWHmy2fJYUVUGXS7_vw.png" /></figure><p>這樣就完成囉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*OujwPTcq-7qw6cXsZxERMA.gif" /></figure><p>感覺<strong>IBSegueAction</strong> 傳值的方式似乎更簡潔，更方便耶！<br>尤其是要接收的那頁可以減少 檢查null?的取值方式!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5aeb1f6d298" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protocol的optional 方法]]></title>
            <link>https://dafu1231.medium.com/protocol%E7%9A%84optional-%E6%96%B9%E6%B3%95-2e868f77e037?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e868f77e037</guid>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[extension]]></category>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Sun, 31 Oct 2021 06:57:43 GMT</pubDate>
            <atom:updated>2021-10-31T06:57:43.662Z</atom:updated>
            <content:encoded><![CDATA[<p>在Swift裡，不論什麼物件，如果有去符合某個protocol的話，預設是要去實現protocol裡全部的方法，但其實如果自己寫protocol，還是可以將protocol裡的方法改為optional就可以不必一定要實現。</p><p>寫一個簡單的protocol</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*68hay5AeNamDjjoTme6tPw.png" /></figure><p>正常情況下，讓viewController符合MyProtocol，會提示須要實現方法</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*Bkr3To6OGjD2sWiGffSKtw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UhaEAVpqU2l6AYosIAduew.png" /></figure><p>這時候可以有兩種方式實現protocol裡的optional方法</p><p>第一個:在方法前加上@objc optional 關鍵字 即可</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*Bkr3To6OGjD2sWiGffSKtw.png" /></figure><p>第二個，使用extension protocol，在extension裡先實現方法 即可</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*Rwyl4ipfZ2RYQpBlFpPUug.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e868f77e037" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UITextView 的間距(Padding?)]]></title>
            <link>https://dafu1231.medium.com/uitextview-%E7%9A%84%E9%96%93%E8%B7%9D-padding-5dd86606232f?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dd86606232f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uitextview]]></category>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[padding]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 15:16:35 GMT</pubDate>
            <atom:updated>2021-09-30T15:16:35.947Z</atom:updated>
            <content:encoded><![CDATA[<p>使用textView時預設會有間距，像這樣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*aVDLEHRM-uNV4qbV6lKk5Q.png" /></figure><p>但如果有時候不想要預設的間距或者對版面比較要求時，也是可以改變裡面的間距的，只要這樣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZqJh1wxaGOA-huKDmxmbg.png" /></figure><pre>override func viewDidLoad() {</pre><pre> super.viewDidLoad()</pre><pre> myTextView.textContainer.lineFragmentPadding = 0 //左右間距</pre><pre> myTextView.textContainerInset = .zero // 上下間距</pre><pre>}</pre><p>效果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*sdbeiMKMH5Mw92sxC519vQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dd86606232f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Present 一個 透明背景的UIViewController]]></title>
            <link>https://dafu1231.medium.com/present-%E4%B8%80%E5%80%8B-%E9%80%8F%E6%98%8E%E8%83%8C%E6%99%AF%E7%9A%84uiviewcontroller-72c3feeddfc0?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/72c3feeddfc0</guid>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[present]]></category>
            <category><![CDATA[uiviewcontroller]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Sun, 29 Aug 2021 08:59:12 GMT</pubDate>
            <atom:updated>2021-08-29T08:59:12.322Z</atom:updated>
            <content:encoded><![CDATA[<p>這是一個滿常用在客製化Alert的首要步驟，但有個小地方需要注意，如果只把present 的UIViewcontroller背景設為透明是不夠的，會變成像這樣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*zt8q7TRTqa6EU-CnbNAZbA.gif" /></figure><p>設為透明後，結果變成全黑的背景</p><p>這時候只要記得設定modalPresentationStyle就可以了！</p><p>overFullScreen或overCurrentContext都可以</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KixGv3RlfeSPf0spiwNgOA.png" /></figure><p>效果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*yh5uMk5rP1JqXZo1j-nBhQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72c3feeddfc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift-從Xcode12 調整UILabel行距(Line Spacing)]]></title>
            <link>https://dafu1231.medium.com/swift-%E5%BE%9Excode12-%E8%AA%BF%E6%95%B4uilabel%E8%A1%8C%E8%B7%9D-line-spacing-d2164f515168?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2164f515168</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uilabel]]></category>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[line-spacing]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 09:24:18 GMT</pubDate>
            <atom:updated>2021-07-31T09:25:12.524Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://dafu1231.medium.com/swift-uilabel%E8%A1%8C%E8%B7%9D-line-spacing-e2b40155fd1d"><strong><em>上一篇</em></strong></a> 的調整行距是從程式碼去做設定，如果想在Xcode IDE直接做調整也是可以的。</p><p>這是為調整前的行距</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*Bb3cvzxdZ5zqPhcLGdKMjw.png" /></figure><p>步驟：</p><p>首先先選到要調整的Label</p><p>接著在右邊的Text 從原本的Plain調整為Attributed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*UClpgLd9rCwfvJeMbu_y0w.png" /></figure><p>選擇最後面的更多，就會彈出可調整的視窗</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*7wZXXq2lKiuvzblsmWfZ8g.png" /></figure><p>調整Spacing，在這裡調整成15</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*eZ-tm4eWZR2s50a2HUGXVA.png" /></figure><p>調整後的行距畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*sCSC8qKNsWQUNu003PWRJw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2164f515168" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift-UILabel行距(Line Spacing)]]></title>
            <link>https://dafu1231.medium.com/swift-uilabel%E8%A1%8C%E8%B7%9D-line-spacing-e2b40155fd1d?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2b40155fd1d</guid>
            <category><![CDATA[line-spacing]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uilabel]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[henry]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 16:38:24 GMT</pubDate>
            <atom:updated>2021-06-29T16:46:30.810Z</atom:updated>
            <content:encoded><![CDATA[<p>其實這是個滿常需要使用到的功能，這次就用程式來做設定，這只是個簡單範例，真正使用應可做成String的Extension會更方便</p><p>在畫面中央放一個UILabel，水平垂直置中，寬高都是200，文字置中，並輸入文字</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WTbyMNXUevPueTQlXq5vWQ.png" /></figure><p>在畫面上預設會是這樣呈現，可以看到預設已經是滿好看了，但如果行與行之間再多一點距離，看起來會更為舒適。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*NxKTYF0jq5YR2mK7XVZ3OA.png" /></figure><p>到程式裡進行設定</p><p>建立一個NSNSMutableParagraphStyle1並設定lineSpacing與alignment</p><p>建立NSAttributedString，並設定他的attributes裡的.Key.paragraphStyle</p><p>將myLabel的attributedText設定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*snR55995KeFsPR5OmFffvw.png" /></figure><p>之後的效果</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*WHwQDHTaylho_YqrG3kv3g.png" /></figure><p>多了那麼一點行距，看起來更好看舒服了~</p><p>以下程式碼:</p><pre>override func viewDidLoad() {</pre><pre>super.viewDidLoad()</pre><pre>    //使用此style來設定lineSpacing</pre><pre>    //這裡要記得如果有設定文字的alignment ，要再次設定，不然會回復到預設靠左</pre><pre>    let paragraphStyle = NSMutableParagraphStyle()</pre><pre>    paragraphStyle.lineSpacing = 8</pre><pre>    paragraphStyle.alignment = .center</pre><pre>    //建立attributes及設定attributed.Key.paragraphStyle</pre><pre>    let attributes = NSAttributedString(string: myLabel.text!,      attributes: [NSAttributedString.Key.paragraphStyle : paragraphStyle])</pre><pre>    //設定label的attributedText</pre><pre>    myLabel.attributedText = attributes</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2b40155fd1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[View的曲線移動動畫]]></title>
            <link>https://dafu1231.medium.com/view%E7%9A%84%E6%9B%B2%E7%B7%9A%E7%A7%BB%E5%8B%95%E5%8B%95%E7%95%AB-e5a33a292983?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a33a292983</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[uibezierpath]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Tue, 25 May 2021 14:59:07 GMT</pubDate>
            <atom:updated>2021-05-25T14:59:07.731Z</atom:updated>
            <content:encoded><![CDATA[<p>這是個讓View做曲線移動的簡單動畫，成果會是這樣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*zv9oWvcHamqDWv51xGKJPg.gif" /></figure><p>讓View做一個有曲線移動的動畫</p><p>首先先在畫面上加上一個正方形的View</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_QKQHHIw8eAOGqbBZEg-g.png" /></figure><p>用UIBezierPath在畫面上畫曲線，而這次不用和他的好朋友CAShapeLayer做搭配，因為我們沒有要將UIBezierPath畫的曲線顯示出來</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3P5GjYRVi02prrrx77fU-g.png" /></figure><p>創造一個CAKeyframeAnimation動畫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zA6aq5MjoH_a39A2UKUuQ.png" /></figure><p>最後記得將這個動畫加到myView的layer上</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXvt-xBM0iBoqGY_njzCGA.png" /></figure><p>完整程式碼</p><pre>override func viewDidLoad() {</pre><pre>super.viewDidLoad()</pre><pre>//在畫面上加上一個view，位置可以隨意設置，因為之後會按照UIBezierPath所畫的路線做動畫</pre><pre>let myView = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))</pre><pre>myView.backgroundColor =  colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1)</pre><pre>view.addSubview(myView)</pre><pre>//在畫面上畫一條曲線</pre><pre>let path = UIBezierPath()</pre><pre>//path的點移動到CGPoint(x: 300, y: 300)</pre><pre>path.move(to: CGPoint(x: 300, y: 300))</pre><pre>//畫曲線的方法</pre><pre>path.addQuadCurve(to: CGPoint(x: 100, y: 300), controlPoint: CGPoint(x: 150, y: 50))</pre><pre>//做一個keyframe的動畫，並設定keyPath為position</pre><pre>let ani = CAKeyframeAnimation(keyPath: &quot;position&quot;)</pre><pre>//動畫時間</pre><pre>ani.duration = 3</pre><pre>//動畫路線</pre><pre>ani.path = path.cgPath</pre><pre>//需要將完成後的狀態保留需將設定以下兩個屬性</pre><pre>ani.fillMode = .forwards</pre><pre>ani.isRemovedOnCompletion = false</pre><pre>//在myView上的layer加上動畫</pre><pre>myView.layer.add(ani, forKey: nil)</pre><pre>}</pre><pre>//需要將完成後的狀態保留需將設定以下兩個屬性</pre><pre>ani.fillMode = .forwards</pre><pre>ani.isRemovedOnCompletion = false</pre><pre>//在myView上的layer加上動畫</pre><pre>myView.layer.add(ani, forKey: nil)</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a33a292983" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift UIButton-Push down Animation when pressed]]></title>
            <link>https://dafu1231.medium.com/swift-uibutton-push-down-animation-when-pressed-464cbe025975?source=rss-fa6d4ca6ffa3------2</link>
            <guid isPermaLink="false">https://medium.com/p/464cbe025975</guid>
            <category><![CDATA[henry]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[uibutton]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Henry Huang]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 15:36:47 GMT</pubDate>
            <atom:updated>2021-04-27T15:36:47.443Z</atom:updated>
            <content:encoded><![CDATA[<p>此篇可搭配上一篇<a href="https://dafu1231.medium.com/swift-get-uicolor-reba-bceb125cb44f">Swift-Get UIColor Rgba</a> 文章<br>這次想做的是一個按鈕往下推的動畫，會有一個按鈕背景搭配</p><p>成果gif圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*D6aRRVNUgtNIYu-5wn2ODg.gif" /></figure><p>在UIButton的extension加上customPushdownView方法</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrMIGf9tYr5TjedEyquNbw.png" /></figure><p>建立動畫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFQKgeTirIsdF-IcXmvZQA.png" /></figure><p>建立按鈕要呼叫的addPushdownBackground方法</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FYw0fMQFrt6Qls5udAuFg.png" /></figure><p>最後按鈕呼叫方法</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPBgmb6ARC7qGWyOvUUl-w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=464cbe025975" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>