gpt4 book ai didi

ios - 基于标题文本高度的 UITableView 部分的页眉/页脚高度

转载 作者:可可西里 更新时间:2023-11-01 03:25:37 25 4
gpt4 key购买 nike

我想知道是否可以使 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;
}

关于ios - 基于标题文本高度的 UITableView 部分的页眉/页脚高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com