這裏是我的UILabel(由什麼是黃色的定義): 如何在不改變字體大小的情況下修剪UILabel的高度以完美地適應文字?
下面是我後添加[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);
請記住,最後的NSLog將始終顯示30.0(字體大小先前設置),即使顯示的字體大小明顯大於30.0較小。
請幫忙。網上似乎有很多,但我似乎無法得到任何工作。
當你在調用'sizeToFit'嗎? – rmaddy
我嘗試在所有內容的末尾添加行。 –
調用'sizeToFit'後顯示標籤的外觀。確保文本沒有換行符或其他空格。 – rmaddy