I would like to know how to programatically "Tighten Letter Spacing"?
This option is available for a UILabel made in a xib file, and is really handy sometimes.
I know this question has been asked before, but I don't see an answer that mentions this beeing available in the interface builder, so I was curious...
You might want to use UILabel property:
allowsDefaultTighteningForTruncation: Bool
and set it to true
. (Default is false
)
According to Apple Documentation:
When this property is set to true, the label tightens intercharacter spacing of its text before allowing any truncation to occur. The label determines the maximum amount of tightening automatically based on the font, current line width, line break mode, and other relevant information.
https://developer.apple.com/reference/uikit/uilabel/1620533-allowsdefaulttighteningfortrunca
You are probably looking for this:
@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth
Property of UILabel
new in iOS6
.
adjustsLetterSpacingToFitWidth
is deprecated as of iOS 7.
You'd now (as of iOS 8) probably want to do something like:
NSAttributedString *as =
[[NSAttributedString alloc] initWithString:@"Kerninating all the strings"
attributes:@{NSKernAttributeName : @(-2.0)}];
label.attributedText = as;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With