我正在根据文本更改 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;
}
谢谢!