我目前在我的uitableview中有2个标题,
我想要实现的是在标题2和标题1的最后一个单元格之间加一个间距。
我目前的代码是:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//filtered list for usd //Flawrence 5/30/18
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 45)];
view.backgroundColor = [UIColor redColor];
view.layer.borderColor = [UIColor blackColor].CGColor;
view.layer.borderWidth = .5;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
button.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
button.imageView.transform = CGAffineTransformMakeScale(5.0, 1.0);
button.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 24);
button.frame = view.frame;
// button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.tintColor = [UIColor blackColor];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.textColor = [UIColor blackColor];
button.titleLabel.font = [UIFont systemFontOfSize:13];
[view addSubview:button];
if (section == 0) {
[button setTitle:@"HEADER 1" forState:UIControlStateNormal];
}
else {
[button setTitle:@"HEADER 2" forState:UIControlStateNormal];
}
return view;
}
答案 0 :(得分:2)
在heightForFooterInSection
检查部分并返回适当的值。并在UIView
中返回透明的viewForFooterInSection
。
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == 0) {
return 0;
} else {
return 10;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc] init];
[footer setBackgroundColor:[UIColor clearColor]];
return footer;
}
为第一个标题添加顶部空间
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//setup header view
if (section == 0) {
view.frame = CGRectMake(0, 0, tableView.frame.size.width, 55);
button.frame = CGRectMake(0, 10, tableView.frame.size.width, 45);
} else {
view.frame = CGRectMake(0, 0, tableView.frame.size.width, 45);
button.frame = CGRectMake(0, 0, tableView.frame.size.width, 45);
}
return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 55;
} else {
return 45;
}
}
答案 1 :(得分:0)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 20.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
答案 2 :(得分:0)