Reputation: 211
With UILabels there seems to be a permanent border of emptiness around the text. Trying things like
label.layoutMargins = UIEdgeInsetsZero;
doesn't do anything and the gap between the top of the text and the top of the label seems to be proportionate to the font size.
Is there a way to make the gap go away? Or is there a way to know how big the gap is?
Upvotes: 0
Views: 160
Reputation: 315
This should give you the gap value:
CGSize labelSize=label.frame.size;
CGSize textSize = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(labelSize.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
// Assuming that the text is centered inside the label
CGFloat topGap = (labelSize.height-textSize.height)/2
Upvotes: 1