gpt4 book ai didi

ios - 限制 UItableView 的页眉 View 和页脚 View 的宽度

转载 作者:行者123 更新时间:2023-11-28 22:19:35 25 4
gpt4 key购买 nike

enter image description here

在下面的屏幕截图中,蓝色线是我的 tableView 部分的页眉和页脚(在 tableView 中,我将行视为部分)。

但是,我希望蓝线刚好位于 tableView 行的下方(与行的宽度相同)。知道怎么做吗??

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 333, 1)] ;
headerView.backgroundColor = [UIColor blueColor];
return headerView;
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 333, 1)] ;
footerView.backgroundColor = [UIColor blueColor];
return footerView;
}

最佳答案

您可以在将背景颜色设置为清除颜色的 UIView 上方添加蓝色的 UIView

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{

UIView *dummyfooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 2)] ;
dummyfooterView.backgroundColor = [UIColor clearColor];

// Widht should be less than dummyfooterView
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 320-20, 2)] ;
footerView.backgroundColor = [UIColor blueColor];
[dummyfooterView addSubview:footerView];
return dummyfooterView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 2;
}

不是很清楚,希望对你有帮助!输出将类似于下面的屏幕。我在这里使用了分组 TableView 样式。

enter image description here

关于ios - 限制 UItableView 的页眉 View 和页脚 View 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20780599/

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