Min Wang
Min Wang

Reputation: 305

How to remove the extra padding below an one line UILabel

I wanna to use a UILabel to show some words which is sent from Server,these words which i set them as NSMutableAttributeString sometimes only occupy one line (only in this case, the problem comes).

I intend to get the exact space which the label would take up,but when the label only takes up one line,and very important — i set the NSMutableAttributeString with lineSpacing (10px,NSMutableParagraphStyle),but this,unexpectedly, would also works when even there is only one line here — the problem shows up as some extra padding below the word (i test with some chinese word,but attention: if the words takes up more than one line, there is no problem). and the weird story is — if the word is purely english or Arabic numerals,the extra padding won't exist)

the following pics may shows the problem a little clearly:

1.English words -- oneline (no extra padding)[test words:today 0987776]

Test with english words

2.Chinese words -- oneline (some extra padding)[test words:今天天气好啊!]

Test with chinese words

Hope someone would help . Thx a lot.

Upvotes: 2

Views: 4277

Answers (2)

CoderYChen
CoderYChen

Reputation: 11

// baselineOffset, It was totally hit and miss Hope to help you

[attributedString addAttribute:NSBaselineOffsetAttributeName value:@(baselineOffset) range:range];

Upvotes: 0

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

use sizeToFit on a label to the size required by the text


[yourlabelName sizeToFit];

any other padding would be from the font, the label itself doesn't apply any other padding

Upvotes: 1

Related Questions