각 필드의 텍스트 길이에 따라 동적으로 높이가 바뀌는 자막 스타일 UITableViewCell이 있습니다. 문제는 레이블에 여러 줄이 있으면 textLabel의 높이 (CGSize 크기)가 증가하지 않는다는 것입니다.NSString sizeWithFont : constrainedToSize : 잘못된 높이 계산
이상한 제품은 detailTextLabel 높이가 정상적으로 (CGSize의 SIZE2)로 증가된다는 것이다. 두 높이를 계산하는 코드는 동일합니다.
cell.textLabel.numberOfLines = 0;
cell.detailTextLabel.numberOfLines = 0;
UPDATE : 덕분에 나는 또한 여러 줄을 지원하기 위해 cellForRowAtIndexPath에서 0 textLabel라는의 numberOfLines 속성을 모두 설정하고
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
SETLISTFMNS0Song *song = [[[selectedSetlist.sets objectAtIndex:indexPath.section] songs]objectAtIndex:indexPath.row];
CGSize size = [song.name sizeWithFont:[UIFont fontWithName:setlistFont size:labelFontSize] constrainedToSize:CGSizeMake(self.setsTable.bounds.size.width, CGFLOAT_MAX)];
NSLog(@"Label: \"%@\" \tLabel Size: %f W %f H", song.name, size.width, size.height);
NSMutableString *detail;
if ([song cover]) {
detail = [[NSMutableString alloc] initWithFormat:@"(%@ cover)", [[song cover] name]];
}
if ([song with]) {
if (!detail) {
detail = [[NSMutableString alloc] initWithFormat:@"(with %@)", [[song with] name]];
}
else {
[detail appendFormat:@" (with %@)", [[song with] name]];
}
}
if ([song info]) {
if (!detail) {
detail = [[NSMutableString alloc] initWithFormat:@"(%@)", [song info]];
}
else {
[detail appendFormat:@" (%@)", [song info]];
}
}
if (detail.length != 0) {
CGSize size2 = [detail sizeWithFont:[UIFont fontWithName:setlistFont size:detailFontSize] constrainedToSize:CGSizeMake(self.setsTable.bounds.size.width, CGFLOAT_MAX)];
size.height += size2.height;
NSLog(@"Detail Label: \"%@\" \tDetail Label Size: %f W %f H", detail, size2.width, size2.height);
}
return size.height + 5;
}
: 여기
내 기능입니다 @ josh에게 나는 왜 이것이 일어나고 있는지 이해합니다. 너비가 너무 넓은 UITableView 너비를 설정할 폭 제약이 있습니다. 누구든지 그것이 만들어지기 전에 UILabel의 너비를 찾는 방법을 알고 있습니까? 하아!감사합니다.
이미지 링크를 올리면 누군가가 당신을 대신해 돌봐 줄 것입니다. –
@ A-Live 아이디어에 감사드립니다. 이미지가 업로드되었습니다. – AUSTOOO