我正在根据文字更改UILabel高度。它工作得很好,但是如果字体大小超过19.0f,我发现只有一个案例不会加载。如果我改变它是没关系的,但我给了用户选项来改变字体大小,所以......
它开始重叠视图,弄乱视图,这里是示例:
以下是我用来调整标签大小的代码:
-(float)resizeToFit{
float height = [self expectedHeight];
CGRect newFrame = [self frame];
newFrame.size.height = height;
[self setFrame:newFrame];
return newFrame.origin.y + newFrame.size.height;
}
-(float)expectedHeight{
[self setNumberOfLines:0];
[self setLineBreakMode:UILineBreakModeWordWrap];
CGSize maximumLabelSize = CGSizeMake(self.frame.size.width,9999);
CGSize expectedLabelSize = [[self text] sizeWithFont:[self font]
constrainedToSize:maximumLabelSize
lineBreakMode:[self lineBreakMode]];
return expectedLabelSize.height;
}
谢谢!