I have a UILabel configured with auto-layout so that its height is based on its internal size of the content, so that it gets taller if it has more lines. I need this to be concentrated along with other elements in the same view. With all the defaults, it works fine.
However, I use my own font, which has too much space. I installed NSMutableParagraphStyle, for example:
NSMutableParagraphStyle *headlineParagraphStyle = [NSMutableParagraphStyle new]; headlineParagraphStyle.lineSpacing = 0.0f; headlineParagraphStyle.maximumLineHeight = 20.0f; headlineParagraphStyle.hyphenationFactor = 0.0f; headlineParagraphStyle.alignment = NSTextAlignmentLeft;
Then I create and set the NSAttributedString as UILabel -attributedText :
NSString *uppercaseHeadline = self.currentStory.headline.uppercaseString; NSAttributedString *attributedHeadline = [[NSAttributedString alloc] initWithString:uppercaseHeadline attributes:@{NSParagraphStyleAttributeName: headlineParagraphStyle}]; self.headlineLabel.attributedText = attributedHeadline;
As a result, the text looks fine, but it grabbed the top of the UILabel and cut off at the top, while there is still extra space at the bottom of the label: 
This also discards the centering of other elements on the text in this label, as you can see that the space between the two lines does not coincide with the center of the label frame.
How can I tell UILabel to re-enter this text so that the top does not crop and there is no space below?
ios cocoa-touch uilabel
Arclite
source share