gpt4 book ai didi

ios - 在节中设置的标题下添加 View

转载 作者:行者123 更新时间:2023-11-29 12:59:39 34 4
gpt4 key购买 nike

我想在 UITableView 的部分标题下添加一个 View 。那可能吗?到目前为止,这是我的代码,用该代码替换了该部分:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 4) {
return 10;
} else
{
return 20;
}
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 4) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor blackColor];
return view;
} else {
return nil;
}
}

最佳答案

从概念上讲,我不会认为这是在标题下添加另一个 View 。相反,请考虑将标题设置为您希望标题的高度 + 黑线的高度。然后,您所要做的就是创建一个附加 View (黑线)并将其添加为标题的 subview ,ex

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor whiteColor];

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, view.frame.size.height - 2.0, view.frame.size.width, 2.0)];
[lineView setBackgroundColor:[UIColor blackColor]];

[view addSubview:lineView];

关于ios - 在节中设置的标题下添加 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130185/

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