<?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 Ankit Srivastava on Medium]]></title>
        <description><![CDATA[Stories by Ankit Srivastava on Medium]]></description>
        <link>https://medium.com/@ankitsrivastava_17874?source=rss-c1ce12885dba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZynARx3_vMp2YOBh.</url>
            <title>Stories by Ankit Srivastava on Medium</title>
            <link>https://medium.com/@ankitsrivastava_17874?source=rss-c1ce12885dba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 22:06:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ankitsrivastava_17874/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[Easy NSAttributedString usage in Swift]]></title>
            <link>https://medium.com/@ankitsrivastava_17874/easy-nsattributedstring-usage-in-swift-8da338cc99b0?source=rss-c1ce12885dba------2</link>
            <guid isPermaLink="false">https://medium.com/p/8da338cc99b0</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[nsattributedstring]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Ankit Srivastava]]></dc:creator>
            <pubDate>Sat, 11 May 2019 05:20:06 GMT</pubDate>
            <atom:updated>2019-05-11T05:20:06.573Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are into iOS development you might have come across a UI screen which looks similar to the contents of below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*_SJURy3LvDvbx59fHYlZdA.png" /><figcaption>First</figcaption></figure><p>As there are multiple fonts and sizes involved in this, the better choice is to go with NSAttributedString instead of two labels and an image view. This is good but the pain area with NSAttributedString string is that it takes a lot of code to setup and if you have something that looks like below you can imagine the amount of code you will have to write to set it up as there are four rows and each with a combination of custom fonts and images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*NqNufZQpy4K8F1JgWyBrYA.png" /><figcaption>Second</figcaption></figure><p>Now let us look at the code which developers usually write to get the output as shown in the first image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11b9badaef51bf6251078478286e7cbe/href">https://medium.com/media/11b9badaef51bf6251078478286e7cbe/href</a></iframe><p>As you can see that is considerable lines of code for setting up one UILabel. Let us try to extract some repetitive code to make our work much easier. We will move the NSAttributedString creation code to String and UIImage extensions and will overload the + operator to combine two attributed strings easily.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc991cb7d611a2ec9fd502f560fbecc0/href">https://medium.com/media/dc991cb7d611a2ec9fd502f560fbecc0/href</a></iframe><p>Post this we can see how this has changed our implementation to just a few lines of code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc92bd23f2e200a048db735f7ee990ba/href">https://medium.com/media/bc92bd23f2e200a048db735f7ee990ba/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8da338cc99b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>