【发布时间】:2015-08-08 19:38:19
【问题描述】:
这是在我将 [shortDescriptionLabel sizeToFit]; 添加到代码末尾之后:
这是第二个示例(显示在 sizeToFit 之后字体大小实际上发生了变化:
这是我添加 [shortDescriptionLabel sizeToFit];到我的代码结尾(很明显,字体大小恢复为 30.0):
我想修剪多余的高度(胡萝卜上方和下方)。我怎样才能做到这一点?这是我当前的代码:
shortDescriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(itemImageView.frame.origin.x+itemImageView.frame.size.width+10, 20, self.tableView.frame.size.width-itemImageView.frame.origin.x- itemImageView.frame.size.width-20-20, tableViewCellHeight/2)];
shortDescriptionLabel.text = itemObject.shortDescription;
shortDescriptionLabel.font = [UIFont boldSystemFontOfSize:30];
shortDescriptionLabel.textAlignment = NSTextAlignmentCenter;
shortDescriptionLabel.adjustsFontSizeToFitWidth = YES;
shortDescriptionLabel.numberOfLines = 0;
shortDescriptionLabel.minimumScaleFactor = 0;
[shortDescriptionLabel setBackgroundColor:[UIColor yellowColor]];
CGFloat fontSize = shortDescriptionLabel.font.pointSize;
NSLog(@"fontSize = %f", fontSize);
请记住,即使显示的字体大小明显小于 30.0,最后一个 NSLog 将始终显示 30.0(之前设置的字体大小)。
请帮忙。网上似乎有很多关于此的内容,但我似乎无法得到任何工作。
【问题讨论】:
-
你什么时候打电话给
sizeToFit? -
我尝试在所有内容的末尾添加该行。
-
显示调用
sizeToFit后标签的样子。确保文本没有换行符或其他空格。 -
maddy 我已经添加了它的外观并提供了第二个示例。我应该提到它是一个多行 UILabel。
标签: ios objective-c uilabel