UITableview добавить пространство над разделом заголовка - PullRequest
0 голосов
/ 31 мая 2018

У меня в настоящее время есть 2 заголовка в моем uitableview,

это иллюстрация enter image description here

Чего я хочу добиться, это поставить интервал между моими заголовками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;
}

Ответы [ 3 ]

0 голосов
/ 31 мая 2018

попробуйте

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

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
          return 10.0f;
}
0 голосов
/ 31 мая 2018

В 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;
    }
}
0 голосов
/ 31 мая 2018
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 20.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...