run*_*mad 7 iphone uitableview nsstring
我有一个UITableView(Grouped!)并且需要计算两种样式的单元格的高度:UITableViewCellStyleDefault和UITableViewCellStyleValue2.
我就是这样做的UITableViewCellStyleDefault:
CGSize textSize = {300.f, 200000.0f};
CGSize size = [myTextString1 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
size.height += 30.0f;
result = MAX(size.height, 44.0f);
Run Code Online (Sandbox Code Playgroud)
并为UITableViewCellStyleValue2:
CGSize textSize = {207.f, 200000.0f};
CGSize size = [myTextString2 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
size.height += 30.0f;
result = MAX(size.height, 44.0f);
Run Code Online (Sandbox Code Playgroud)
我的问题是他们返回不正确的高度,我认为这是textSize我使用错误数字的地方.对于长文本,底部部分被缩短(通常只是一条带有几个单词的行),对于两个CellStyles,它们在单元格中的文本上方和下方都有奇怪的间距.
因为UITableViewCellStyleValue2我得到了宽度size(207.0f),使text.backgroundColor变为红色,然后只计算盒子的大小.300.0f宽度UITableViewCellStyleDefault是指细胞的大小UITableViewStyleGrouped.
有谁知道我需要使用哪些值来正确计算a的大小,NSString从而为我的细胞获得合适的高度?
谢谢
这是我正在使用的代码.它就像一种细胞的魅力.它可能对您的应用程序有一些有用的部分.
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath {
AppAppDelegate *appDelegate = (AppAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *Text = ([[appDelegate.myTextSectionsDelegateDict objectAtIndex:indexPath.section] objectForKey:@"Text"]);
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [Text sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 15;}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14099 次 |
| 最近记录: |