Friday 2 December 2016

Set attributed text in interface builder

 1) Increase font size as size of UILabel increases:

There may be a requirement to increase the font size as the size of UILabel increases.To see this in action, Open Xcode and switch to xib/storyboard file and follow these steps:

Take a UILabel and  set height of the UILabel to the proportional to the height of screen . and set other required constraint on UILabel.
Then set some properties of UILabel to have font size proportional to the size of UILabel.

a) Set AutoShrink to minimum font size
b) set number of lines to 0
c) set the font size bigger as the maximum size of UILabel .


2) Set Attributed text in interface builder for a UILabel:

We can set attributed text programatically by setting different attributes like font, color, size on a attributed string(instance of NSAttributedString) . But there is an easy way , we can create an attributed text without typing even a single line of code.

We can create an attributed text in interface builder. To set attributed text for a UILabel :

a) Change text type  plain to attributed  in the attributes inspector window.
b) Then type the string as your requirements.
c) Then select  word you want to change the appearance  of and change it's size, font family, color etc. 

No comments:

Post a Comment