Search code examples
objective-cuilabelletter-spacing

How to enlarge UILabel width (letter spacing) in Objective-C?


This is the code I am using for the UILabel title of my View Controller:

UIFont *bebasFont = [UIFont fontWithName:@"Bebas" size:100]; RestaurantsTitle.font = bebasFont; RestaurantsTitle.text = @"RESTAURANTS";

and I need to enlarge the space between the letters of the title but I don't know how to do it.

Setting a width to the text field and not the frame would also work if that is also possible?


Solution

  • I need to enlarge the space between the letters

    Use NSAttributedString and increase the kerning of the string.

    https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/index.html

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/doc/c_ref/NSKernAttributeName