Book Image

Swift Cookbook

Book Image

Swift Cookbook

Overview of this book

Table of Contents (18 chapters)
Swift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Beautifying your text


Have you ever heard the phrase, "The quick brown fox jumps over the lazy dog?" Why is it so famous? The reason is that it is an English pangram, which means a phrase with every letter from the alphabet.

Pangrams are useful when you want to visualize properties of a font, such as size, color or bold. In this recipe, we will check different fonts using NSAttributedString and playground.

Getting ready

Create a new playground called Chapter 6 Text and remove the string that comes with itby default.

How to do it...

To add the beautifying text feature, follow these steps:

  1. First, let's create our attributed string:

    var string = NSMutableAttributedString(string: "The quick brown fox jumps over the lazy dog")
  2. After this, you will see a new icon with the letter appearing, which means that the playground has recognized it as an attributed string. Click on the quick look icon, and you will see the current string with its attributes.

  3. Now, let's choose some font sizes and colors for our text...