Ios UITableview在标题部分上方添加空间
我的uitableview中当前有2个标题 这是一个例子 我想要实现的是在标题2和标题1的最后一个单元格之间设置一个间距 我目前的代码是:Ios UITableview在标题部分上方添加空间,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我的uitableview中当前有2个标题 这是一个例子 我想要实现的是在标题2和标题1的最后一个单元格之间设置一个间距 我目前的代码是: -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { //filtered list for usd //Flawrence 5/30/18 UIView *view = [[UIView alloc] initWi
-(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;
}
试试这个
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 10.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 10.0f;
}
试试这个
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 10.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 10.0f;
}
在
heightforfooterInstitution
检查部分并返回适当的值。并在viewforfooterInstruction
中返回透明的UIView
-(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;
}
}
在
heightforfooterInstitution
检查部分并返回适当的值。并在viewforfooterInstruction
中返回透明的UIView
-(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;
}
}
在tableview的底部有一个突然的额外空间,我正在查找错误在tableview的底部有一个突然的额外空间,我正在查找错误感谢这一点,但是是否还有一种方法可以在标题1的顶部添加一个间距?在viewForHeaderInSection中,如果section==0{button.frame.origin.y=10}并在剖面中将视图高度增加100@FreelancsAndroidLovesyou检查新的注释表达式是否不可赋值。我应该使用cgrectmake吗?谢谢,但是在viewForHeaderInSection中,如果section==0{button.frame.origin.y=10}并且在section中将视图高度增加10,是否也有办法在标题1的顶部添加间距0@FreelancsAndroidLovesyou检查新的注释表达式是否不可赋值。我应该使用cgrectmake吗?