{"id":5650,"date":"2016-12-19T17:12:59","date_gmt":"2016-12-20T01:12:59","guid":{"rendered":"https:\/\/blog.mhvt.net\/?p=5650"},"modified":"2016-12-19T17:12:59","modified_gmt":"2016-12-20T01:12:59","slug":"ios-swift-making-custom-rounded-corner-progress-bar-with-uiview","status":"publish","type":"post","link":"https:\/\/blog.mhvt.net\/?p=5650","title":{"rendered":"iOS &#038; Swift &#8211; Making Custom Rounded-Corner Progress Bar With UIView"},"content":{"rendered":"<p><a href=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"mac\/mac_shareware\/iphoneImage.jpg\" width=\"120\" height=\"120\" alt=\"iPhone custom slider\" \/><\/a><br \/>\n<br \/><\/br><br \/>\n<br \/><\/br><br \/>\nTOKYO (MacHouse) &#8211; About a week ago, I spotted a <a href=\"http:\/\/stackoverflow.com\/questions\/41094232\/how-to-make-a-rounded-corner-progress-bar-like-this-one-in-ios#comment69395931_41094232\">topic<\/a> at <strong>stackoverflow<\/strong> where somebody wanted to know how to create a custom progress bar with a rectangle with rounded corners.  And I thought to myself &#8220;Hmm&#8230;  I wonder if I could do it simply by using a custom <strong>UIView<\/strong> class?&#8221;  So I launched <strong>Xcode 8<\/strong> and started writing code in <strong>Swift<\/strong> (Swift 3).  And voila!  I guess, it&#8217;s not that bad. (See Screenshot 1.)<!--more--><br \/>\n<br \/><\/br><\/p>\n<table width=\"464\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td width=\"220\" valign=\"top\"><a href=\"mac\/mac_shareware\/roundprogress\/roundprogressSimulator.png\"><img loading=\"lazy\" decoding=\"async\" src=\"mac\/mac_shareware\/roundprogress\/_thumbnail_roundprogressSimulator.jpg\" width=\"220\" height=\"406\" alt=\"iOS Swift custom progress bar\"\/><\/a><\/a><\/p>\n<div align=\"center\">Screenshot 1<\/div>\n<\/td>\n<td width=\"20\">&nbsp;<\/td>\n<td width=\"220\" valign=\"top\"><a href=\"mac\/mac_shareware\/roundprogress\/roundprogressXcode.png\"><img loading=\"lazy\" decoding=\"async\" src=\"mac\/mac_shareware\/roundprogress\/_thumbnail_roundprogressXcode.jpg\" width=\"220\" height=\"129\" alt=\"iOS Swift custom progress bar\"\/><\/a><\/a><\/p>\n<div align=\"center\">Screenshot 2<\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p><\/br><br \/>\nIn order to create a progress bar like the one shown in Screenshot 1, you probably want to subclass UIView so that you can curve corners of a rectangle, which is an instance of a UIView subclass.  let sleepTime = UInt32(animationPeriod\/100 * 1000000)  In my example, I&#8217;m making progress artificial with sleep like<br \/>\n<br \/><\/br><br \/>\n<code>let sleepTime = UInt32(animationPeriod\/100 * 1000000)<\/code><br \/>\n<br \/><\/br><br \/>\nClick <a href=\"mac\/mac_shareware\/roundprogress\/roundprogress.mov\">here<\/a> to watch a quick iPhone Simulator QuickTime movie.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TOKYO (MacHouse) &#8211; About a week ago, I spotted a topic at stackoverflow where somebody wanted to know how to create a custom progress bar with a rectangle with rounded corners. And I thought to myself &#8220;Hmm&#8230; I wonder if &hellip; <a href=\"https:\/\/blog.mhvt.net\/?p=5650\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":342,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[504,507],"tags":[],"class_list":["post-5650","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift"],"_links":{"self":[{"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/posts\/5650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/users\/342"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5650"}],"version-history":[{"count":4,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/posts\/5650\/revisions"}],"predecessor-version":[{"id":5654,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=\/wp\/v2\/posts\/5650\/revisions\/5654"}],"wp:attachment":[{"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mhvt.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}