我想知道是否可以使 UITableView 的一部分的页眉/页脚高度等于页眉/页脚标题文本的高度。任何提示都会很棒!
注意:我的 TableView 的某些部分可能没有页眉/页脚,在这种情况下,部分之间只有填充,因为在这种情况下“headerTitleHeight/footerTitleHeight”将为零。
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return headerTitleHeight + padding;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return footerTitleHeight + padding;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
NSString *myHeader = [sectionsArray objectAtIndex:section];
CGSize maxSize = CGSizeMake(320, 999999.0);
int height = 0;
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
nil];
if (IS_IOS_6) //Macro i made for if iOS 6
{
CGSize size = [myHeader sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:(15)]
constrainedToSize:maxSize
lineBreakMode:NSLineBreakByWordWrapping];
height = size.height;
}
else // IOS 7 , Attributes
{
CGRect frame = [myHeader boundingRectWithSize:maxSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributesDictionary
context:nil];
height = frame.size.height;
}
return height+5;
}
Tôi là một lập trình viên xuất sắc, rất giỏi!