4

I calculate the size of a UILabel (only height matters here) by dynamic length text. And I draw the label's layer's border to visualize the frame of the label. I see "padding" above and under the label text sometimes, but not always. I do not want the padding. I suspect it relates to attributed string, since I never encounter such problem in a "normal" string label.

I see this (Note the padding of the first row):

enter image description here

I want this:

enter image description here

Relevant code:

-(void)setupQuestionView
{
    [self.questionView setAttributedText:[self.allContents[_itemIndex] objectForKey:@"Question"]];

    // new question view height
    CGSize constraint = CGSizeMake(kCellWidth - kLeftMargin - kRightMargin, FLT_MAX);

    CGSize size = [self.questionView.text sizeWithFont:[UIFont systemFontOfSize: kFontSize] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];

    [self.questionView setFrame:CGRectMake(kRightMargin, kTopMargin, kCellWidth - kRightMargin * 2, size.height)];

    [self.questionView.layer setBorderWidth:1.0f];      // debug
}
4

1 に答える 1

1

kLeftMargin と kRightMargin は等しいか? 他の場所がうまくいかない可能性があることを見つけることができませんでした。

于 2013-01-31T12:06:43.917 に答える