<?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 Hari Sukumar Mandava on Medium]]></title>
        <description><![CDATA[Stories by Hari Sukumar Mandava on Medium]]></description>
        <link>https://medium.com/@hari.sukumar64?source=rss-42f4800fb957------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4MxvqB09S0VgNQtL</url>
            <title>Stories by Hari Sukumar Mandava on Medium</title>
            <link>https://medium.com/@hari.sukumar64?source=rss-42f4800fb957------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:23:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hari.sukumar64/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[Change the layout of views based on device orientation]]></title>
            <link>https://medium.com/@hari.sukumar64/change-the-layout-of-views-based-on-device-orientation-53a37fba6f77?source=rss-42f4800fb957------2</link>
            <guid isPermaLink="false">https://medium.com/p/53a37fba6f77</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[autolayout-constraints]]></category>
            <category><![CDATA[orientation]]></category>
            <dc:creator><![CDATA[Hari Sukumar Mandava]]></dc:creator>
            <pubDate>Sat, 13 Jul 2019 11:46:07 GMT</pubDate>
            <atom:updated>2019-07-13T11:46:07.681Z</atom:updated>
            <content:encoded><![CDATA[<p>In iOS, if you have to create an app that should work in both Landscape and portrait orientations, which way you will choose to achieve this?</p><p>You can do it in multiple ways:</p><ol><li>Playing with constraints programmatically.</li><li>Adding constraints for views in storyboards using “Vary for traits”.</li><li>Using UIStackView</li></ol><p>When compared to storyboards, constraints those are created programmatically will work faster. In this article, I am going to cover the first approach.</p><p>I will show you how to add views programmatically using two views “<strong>GreenView</strong>” and “<strong>RedView</strong>”.</p><ol><li>The first and foremost step to add constraints programmatically is to disable <strong><em>translatesAutoresizingMaskIntoConstraints</em></strong><em>.</em></li></ol><p>2. Then, create both views programmatically:</p><figure><img alt="Creating view programatically" src="https://cdn-images-1.medium.com/max/1024/1*2vkcNyWDke1P-kQshYb11A.png" /><figcaption>Creating a view programmatically.</figcaption></figure><p>3. Add constraints to views for <strong>portrait</strong> mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hl8ByoJV_Qs3PqryaWWyCg.png" /></figure><p>4. Add constraints to views for <strong>landscape</strong> mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6pU4SGTw3mLfu-gM7h3jOA.png" /></figure><p>5. In the above step, We have added constraints to views but we didn’t activate them. Based on the device orientation we have to activate/deactivate these constraints. For this, we’ve to observe device orientation notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0QdEK98OowCGk2c5Og9uw.png" /></figure><p>6. Activation/deactivation of constraints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_XNbgr_spLy-ESvekZtjpg.png" /></figure><p>It’s done. Now you can rotate your device and it works like a charm.</p><p>Thanks for reading.</p><p>You can connect me @ <a href="https://www.linkedin.com/in/hari-sukumar-3a613b79/">https://www.linkedin.com/in/hari-sukumar-3a613b79/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53a37fba6f77" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>