"sizeWithFont"를 사용 거기에 많은 솔루션 또는 여기계산 셀 높이 7
아이폰 OS 7 추천되지 할 일이 비슷한이있다 내가 함께 재현 한 몇 가지 코드되어 있습니다 지금까지. 높이가 변경되지만 전혀 정확하게 : 또 다른 예를 들어
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = "The Cell's Text!";
cell.textLabel.numberOfLines = 0;
[cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping];
[cell.textLabel sizeToFit];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBounds.size;
NSAttributedString *aString = [[NSAttributedString alloc] initWithString:"The Cell's Text!"];
UITextView *calculationView = [[UITextView alloc] init];
[calculationView setAttributedText:aString];
CGSize size = [calculationView sizeThatFits:CGSizeMake(screenSize.width, FLT_MAX)];
return size.height;
}
, 여기에 유사한 대답 : https://stackoverflow.com/a/9828777/693121를 내가 전에 말했듯이,이되지 않는 코드를 사용하지만.
. Apple의 docs에서 : "한 줄에 지정된 글꼴로 렌더링 할 문자열의 크기를 반환합니다." 다중 행 레이블을 기반으로 셀 높이를 변경하려는 경우 유용하지 않습니다. – rdelmar