gpt4 book ai didi

ios - UITableView 如何添加自定义 UIImageView 作为分隔符并设置自定义位置

转载 作者:行者123 更新时间:2023-11-28 22:17:55 26 4
gpt4 key购买 nike

我有一个包含多个部分(不是行)的 UITableView。我想将 UIImageView 添加为中心每个部分之间的分隔符(最后一个单元格除外)。单元格间距为30

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor clearColor];
return headerView;
}

截图

我想像截图那样设置位置。 enter image description here

我写的代码

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

单元格高度为81。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Some code
UIImageView *separatorIView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 96, 196, 2)];
[separatorIView setImage:[UIImage imageNamed:@"grayline.png"]];
[cell.contentView addSubview:separatorIView];
return cell;
}

如果我设置 y 坐标 < 然后单元格高度,就会出现灰线。提前致谢。

结果

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor clearColor];
if (section > 0) {
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(62, 14, 196, 2)];
[img setImage:[UIImage imageNamed:@"grayline.png"]];
[headerView addSubview:img];
}
return headerView;
}

最佳答案

自定义分隔符位置是不可能的,因为它们是为它的框架私有(private)定义的,除此之外,如果你需要那种效果,那么你必须在标题中添加一个图像,比如自定义空间和颜色,只有你可以获得所需的 View

关于ios - UITableView 如何添加自定义 UIImageView 作为分隔符并设置自定义位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21132687/

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