【发布时间】:2012-07-09 08:47:54
【问题描述】:
是否可以有一个多行 UILabel 自动调整 UIFont 大小以适应 UILabel 的框架大小?如果没有,那么实现这一目标的最佳方法是什么?我不想将 UILabel/UITextView 的帧大小调整为任何值。到目前为止,我一直在这样做:
int currentFontSize = 18;
UIFont *currentFont = [UIFont fontWithName:kProximaNovaBold size:currentFontSize];
CGSize storyTitleSize = [storyTitle sizeWithFont:currentFont constrainedToSize:self.newsfeedStoryTitle_.frameSize];
while (storyTitleSize.height >= self.newsfeedStoryTitle_.frameHeight){
currentFontSize--;
currentFont = [UIFont fontWithName:kProximaNovaBold size:currentFontSize];
storyTitleSize = [storyTitle sizeWithFont:currentFont constrainedToSize:self.newsfeedStoryTitle_.frameSize];
}
[self.newsfeedStoryTitle_ setFont:currentFont];
[self.newsfeedStoryTitle_ setText:storyTitle];
【问题讨论】:
标签: objective-c ios uilabel