Changes

Working with Fonts and Attributed Strings in WatchKit

12 bytes added, 21:00, 1 February 2016
m
Text replacement - "<google>BUY_WATCHKIT</google>" to "<htmlet>watchos2_upgrade</htmlet>"
<googlehtmlet>BUY_WATCHKITwatchos2_upgrade</googlehtmlet>
The above example uses an attributed string to set one attribute for the entire text string. In practice, attributed strings can contain multiple attributes covering different ranges of characters within the string. Multiple attributes within an attributed string require the use of the NSMutableAttributedString class. Once an instance of this class has been created and initialized with a string, the addAttribute method may be called to add attributes for ranges of characters in the string. For the purposes of the example project, this approach will be used to change the colors used to render the words “Apple” and “Watch” in the label in Figure 23 3. The code to achieve this reads as follows:
<googlehtmlet>BUY_WATCHKITwatchos2_upgrade</googlehtmlet>
<pre>
let headlineFont =
<googlehtmlet>BUY_WATCHKITwatchos2_upgrade</googlehtmlet>