<?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 Osama Azmat Khan on Medium]]></title>
        <description><![CDATA[Stories by Osama Azmat Khan on Medium]]></description>
        <link>https://medium.com/@osamaazmat?source=rss-ea6536e632eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bYUAAUwR2QsGCXFL10A-7A.png</url>
            <title>Stories by Osama Azmat Khan on Medium</title>
            <link>https://medium.com/@osamaazmat?source=rss-ea6536e632eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:33:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@osamaazmat/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 Left Right UI Slider with Origin at Center]]></title>
            <link>https://medium.com/@osamaazmat/swift-left-right-ui-slider-with-origin-at-center-66b23ef868b7?source=rss-ea6536e632eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/66b23ef868b7</guid>
            <category><![CDATA[center]]></category>
            <category><![CDATA[slider]]></category>
            <category><![CDATA[center-origin-slider]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[two-way]]></category>
            <dc:creator><![CDATA[Osama Azmat Khan]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 09:10:58 GMT</pubDate>
            <atom:updated>2021-01-24T09:10:58.036Z</atom:updated>
            <content:encoded><![CDATA[<p>So I came across a situation in which I had to implement a UISlider which had its initial value of 0 but -ve and +ve minimum and maximum values on the extreme left and right respectively.</p><p>It had to be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4zHFT10iUUsGYSj45I-Iw.png" /></figure><p>As you see, the slider should start filling from the center. This is not readily available with the UISlider that we have.</p><p>So, this is what I did.</p><h4>Setup:</h4><ol><li>Add a UISlider to the view controller via storyboard and give it the leading, trailing, vertically center constraints as required.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*4o7tVoDHx3LunekLsYtIHA.png" /></figure><p>2. Create IBOutlet to the respective View Controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*MpZGx9XF5tvBKkVUJvtcuQ.png" /></figure><p>3. Add another view from the storyboard and give it the following constraints:</p><ul><li>View.Leading -&gt; twoWayRangeSlider.CenterX</li><li>View.Trailing -&gt; twoWayRangeSlider.CenterX</li><li>View.Height -&gt; as Required (Preferred -&gt; 5)</li><li>View.CenterY -&gt; twoWayRangeSlider.CenterY</li></ul><p>This view is going to act as a filler. What we achieved by giving it the above constraints is that we want it to stay in the center of the UISlider vertically and expand to its right and left when the slider value changes respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*p-pf4S8df7-F_XThDqJKBg.png" /></figure><h4>Constraints:</h4><p>(Move to the next section if you know how to implement these)</p><ul><li>View.Leading -&gt; twoWayRangeSlider.CenterX:</li></ul><p>First select the view, give it a leading constraint to the twoWayRangeSlider.Leading. Just as you normally would.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*Sx2vB51CsAHA40pztHgOPg.png" /></figure><p><strong>Select the constraint and Move to the CONSTRAINT’s Attributes Inspector.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*za7Wr1XRNMUb7x62s-a75w.png" /></figure><p>Select the second Item and change it to twoWayRangeSlider.CenterX:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*9Lt1KnMMtAWWQQ4eHqXU0Q.png" /></figure><ul><li>View.Trailing -&gt; twoWayRangeSlider.CenterX:</li></ul><p>Do the same for the trailing constraint of the view. Select the constraint, move to the attributes inspector, and select CenterX for the second item which is the twoWayRangeSlider.</p><p>Yaasss We are halfway there!!!</p><h4>Code:</h4><p>First, create IBOutlets for the Leading and Trailing Constraints of the view. We need these outlets to change the values of the constants. Do this by selecting the constraint from your storyboard, press CTRL + Click and drag to your ViewController.</p><p>(Short Cut to open up your VC is CMD+OPT+CTRL+Return)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*FvHHRJJf8X5b1vFjWBThMg.png" /></figure><p>Your code should now look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYXo98V5laphKH2Vu7aqKA.png" /></figure><p>This is where the magic happens. Move to your ViewController’s class and Create a setup function for your slider. We are keeping the maximum and minimum track color the same because we don&#39;t want the original color overlay of the slider to be visible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ue3fs_x1Fwck8TPiV5O_5Q.png" /></figure><p>Suggestion: Keep the thumbTintColor same as the fill color view’s background color. This will mash the two together and create a uniform look.</p><p>Start and end values are the minimum and maximum values required by the slider. The initial slider value should be the middle value of the start and end values to keep the thumb at the center initially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nawJwYO9hSwrvz5kwHnZzA.png" /></figure><p>Now, create an action handler by adding valueChanged target to the range slider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f_BMa47PeWh71kBTF7LQlA.png" /></figure><p>In this value changed function, we have to figure out the width of our “fill color view” by changing its constraints. What we need to achieve is that when the slider value decreases from the middlemost value (in my case 0), the fill color view’s leading constraint’s constant should increase, and its trailing constraint should be 0, thus creating an illusion that the slider is moving left.</p><p>Similarly, when the slider value increases from the middlemost value we need to increase the trailing constraint’s constant and making its leading constraint to 0. Again, creating an illusion that the slider is moving right.</p><p>What we need to figure out is much should the constant increase or decrease when the slider moves. We do this by first dividing the total width of the slider by 2 (To get the width of one side). Then divide it by the absolute value of the endValue (if you’re moving right) or by the startValue (if you’re left). We achieve this by writing the following function.</p><pre><strong>func</strong> updateValues() {</pre><pre>print(twoWayRangeSlider.value)</pre><pre><strong>self</strong>.fillColorLeadingConstraint.constant = 0</pre><pre><strong>self</strong>.fillColorTrailingConstraint.constant = 0</pre><pre><strong>if</strong> twoWayRangeSlider.value &gt; 0 {</pre><pre><strong>let</strong> widthMultiplier = (twoWayRangeSlider.layer.frame.width / 2) / CGFloat(abs(endValue))</pre><pre><strong>self</strong>.fillColorTrailingConstraint.constant = (CGFloat(CGFloat(twoWayRangeSlider.value) * widthMultiplier)) - 5</pre><pre>}</pre><pre><strong>else</strong> <strong>if</strong> twoWayRangeSlider.value &lt; 0 {</pre><pre><strong>let</strong> widthMultiplier = (twoWayRangeSlider.layer.frame.width / 2) / CGFloat(abs(startValue))</pre><pre><strong>self</strong>.fillColorLeadingConstraint.constant = (CGFloat(CGFloat(twoWayRangeSlider.value) * widthMultiplier)) + 5</pre><pre>}</pre><pre>}</pre><pre><strong>self</strong>.fillColorTrailingConstraint.constant = (CGFloat(CGFloat(twoWayRangeSlider.value) * widthMultiplier)) - 5</pre><pre>}</pre><pre><strong>else</strong> <strong>if</strong> twoWayRangeSlider.value &lt; 0 {</pre><pre><strong>let</strong> widthMultiplier = (twoWayRangeSlider.layer.frame.width / 2) / CGFloat(abs(startValue))</pre><pre><strong>self</strong>.fillColorLeadingConstraint.constant = (CGFloat(CGFloat(twoWayRangeSlider.value) * widthMultiplier)) + 5</pre><pre>}</pre><pre>}</pre><p>Thats it, we did it. Wasnt that easy!</p><p>Run the project and this is what we get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9m8JpxHEpfnqZwSvVfYUfg.gif" /></figure><h4>Repo:</h4><p><a href="https://github.com/osamaazmat/SwiftCenterSlider">osamaazmat/SwiftCenterSlider</a></p><p>Let me know if you yous need me to add something to it. Thank you for reading, Happy Coding :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66b23ef868b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Credit/Debit Card UI in Swift with CreditCardViewSwift]]></title>
            <link>https://medium.com/@osamaazmat/easy-credit-debit-card-ui-in-swift-with-creditcardviewswift-8e41c5999f17?source=rss-ea6536e632eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e41c5999f17</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[credit-card-view]]></category>
            <category><![CDATA[cards]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[payments]]></category>
            <dc:creator><![CDATA[Osama Azmat Khan]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 16:49:34 GMT</pubDate>
            <atom:updated>2020-06-02T17:16:06.512Z</atom:updated>
            <content:encoded><![CDATA[<p>While making a new iOS app’s payment method, there is a huge overhead to create a payment card UI from scratch. This is where <strong>CreditCardViewSwift</strong> comes in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*zizFSfswU7nmma6CzZ6sRg.gif" /><figcaption>Credit Card View Swift — May 2020</figcaption></figure><p>This a complete framework that provides a fully validated and fully functional Payment UI. All you need to do is to add this pod to your application, complete basic setup and its good to go.</p><p>Main features:</p><ul><li>Name Validation</li><li>Credit/Debit/Master card validation through luhn’s method</li><li>Card Expiry Validation</li><li>Properly formatted UI</li><li>Very easy integration through storyboards or programmatically.</li></ul><p>Start off by creating a new project and going through the basic setup. add cocoapods and a podfile to your project. Basic setup of using cocoapods with swift project can be seen from here:</p><p><a href="https://guides.cocoapods.org/using/using-cocoapods.html">CocoaPods Guides</a></p><p><strong>Github Link: </strong><a href="https://github.com/osamaazmat/CreditCardViewSwift">https://github.com/osamaazmat/CreditCardViewSwift</a></p><p>Steps to integrate CreditCardViewSwift into your project using cocoapods:</p><p>You want to add pod &#39;CreditCardViewSwift&#39;, &#39;~&gt; 1.0&#39; to your Podfile. It should look something similar to this.</p><pre>target &#39;MyApp&#39; do<br>  pod &#39;CreditCardViewSwift&#39;, &#39;~&gt; 1.0&#39;<br>end</pre><p>Then run a pod install inside your terminal</p><p>After the successful installation of the framework. Proceed to the storyboard and create a view. Give that view the class of CreditCardViewSwift. It will set it up to show you the layout of the end result.</p><p>After that, import CreditCardViewSwift into your view controller. You have to set the delegate of CreditCardViewSwift to the view controller itself so that it can return you the validated data.</p><p>Xcode will then automatically ask you to implement the delegate methods. There is only one method “cardDataValidated” that has to be implemented. Once you implement it, you will start recieving the card data just as the user adds validated data. Finally your view controller should look something similar to this:</p><pre>import UIKit<br>import CreditCardViewSwift<br><br>class ViewController: UIViewController {<br><br>    @IBOutlet weak var creditCardView: CreditCardViewSwift!<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        creditCardView.delegate = self<br>    }<br>}<br><br>extension ViewController: CreditCardViewSwiftDelegate {<br>    func cardDataValidated(name: String, cardNumber: String, cardExpiry: String, cvvNumber: String) {<br>        //Once Validated, this delegate method will return all the validated data<br>    }<br>    <br>    <br>}</pre><p>Please let me know if you have any questions or you need any features added to this framework. Thankyou so much for your support.</p><p>See you in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e41c5999f17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SkeletonView Animation in Swift UITableView]]></title>
            <link>https://medium.com/@osamaazmat/skeletonview-animation-in-swift-uitableview-d5508f2a736c?source=rss-ea6536e632eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5508f2a736c</guid>
            <category><![CDATA[skeleton-views]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Osama Azmat Khan]]></dc:creator>
            <pubDate>Tue, 28 May 2019 12:26:04 GMT</pubDate>
            <atom:updated>2019-05-30T07:44:03.126Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*NWBhlKsDGoAYvV_1nVSjfw.png" /></figure><p>So are you like me and couldn&#39;t find a way to animate your table view while your service returned with the data?</p><p>I guess you are. So after looking for a few options like <a href="https://lottiefiles.com/">lottie</a> etc, a <a href="https://twitter.com/Shoaib_dev">friend</a> of mine (Who happens to be one of the best developers I know) told me to use <a href="https://github.com/Juanpe/SkeletonView">Skeleton View</a> by Juanpe. Its a great library which is updated frequently and the owner replies quite quickly aswell. Also its compatible with swift 5.</p><p>So I would like to get to the point and show you guys how I implemented this. I think this is the easiest implementation you’d find. So without wasting further time, add the library to your project:</p><p><strong>Using </strong><a href="https://cocoapods.org/"><strong>CocoaPods</strong></a><strong>:</strong></p><pre>pod &quot;SkeletonView&quot;</pre><p><strong>Using </strong><a href="https://cocoapods.org/"><strong>Carthage</strong></a><strong>:</strong></p><pre>github &quot;Juanpe/SkeletonView&quot;</pre><p>Once SkeletonView is successfully added, build and check if the project runs smoothly. We have to import SkeletonView and after setting up our view controller, we have to add a flag to see if we want to animate the view or our service call has returned with our data and thus have to stop showing the animation. I have put an arbitrary delay to mimic service call delay. You should ideally call your service rather than the forced delay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*531a_yTvqJ0metla24p2FQ.png" /></figure><p>Then we have to setup our UITableView DataSource and Delegate methods. The flag tells us either we have to animate the cell or not. There are quite a few options for animation styles, e.g., Solid, Gradient, Animated Gradient etc:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Um5tYxEcwi7dzAixns0uWA.png" /></figure><p>Once we have setup the UITableView we have to add a Data Source method for Skeleton View Data Source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w71Thv7s1hLOc6Vi4tCr9w.png" /></figure><p>After we have setup our view controller completely, lets setup our cell. For that, add a new UITableViewCell Class and check “Also create xib file” option. We add the labels and images or whatever we require to be in our cell. One of the most important part is to <strong>select all the components you add and from the attributes inspector, Select view “is Skeletonable” to “ON”</strong>. Note that the Cell, Its content view and all the components inside should be skeletonable = ON for this to work smoothly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0YqU7KrhiCDQP6rsxiQkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*VDg8vrSHXJZKQsfnyCfyvw.png" /></figure><p>In the UITableView method number of rows in section, we have returned 10. We can return any number there according to the result of our service call. we can also use our flag to check how many items to return.s</p><p><strong>Final Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*oPSPc7Yv5uXtzreHLWXjhA.gif" /></figure><p>Build and run, it should work smoothly. Please let me know of your feedback/comments below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5508f2a736c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>