Blessed Mama PNG Sublimation Graphics Clipart

Start using it instantly after download for your t-shirt design, mug design, product graphics, stickers, scrapbooking, heat transfer projects, wall art, crafts, blog posts, store banners, website…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Easy NSAttributedString usage in Swift

If you are into iOS development you might have come across a UI screen which looks similar to the contents of below image.

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.

Second

Now let us look at the code which developers usually write to get the output as shown in the first image.

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.

Post this we can see how this has changed our implementation to just a few lines of code.

Add a comment

Related posts:

The Emergent Field of Interaction Architecture and the Future of Work

My friend proposed a simple game to our group: each person would put their favorite song from the past month into a shared playlist. Then we would go around, listen to each song, and talk about it…

How to use Volta and why you should consider it over nvm

Node.js is alive and well, they’ve released version 17 into the ecosystem on October 19th, 2021. Along with Node.js 17 brings npm 8 and many cool new features. Now as you go to try it out, it’s also…

Intel c600 series chipset driver windows 10

Download the Intel Chipset Software Installation 10.1.1.8 WHQL driver. This this one actually updates a lot of things. The Intel Chipset Software Installation Utility installs the Windows* INF. …