Alessio Crestani Alessio Crestani - 1 year ago 78
iOS Question

Keep UITableView padding on header but no in separator on IOS7

with the transition on iOS7 the separator has 15px padding on left. I know that i can remove this padding with separator inset feature on the UITableView setting in the xib file, but i need to keep heading text with padding. How to do it?


enter image description here

with custom on separator inset to 0:

enter image description here

i need to keep separators like figure 2, but the header with "2013" like picture 1.

Answer Source

for Seperator you can set it via Storyboard

and for header make a custom header like this

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
  UIView *viewHeader = [UIView.alloc initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 28)];
  UILabel *lblTitle = [UILabel.alloc initWithFrame:CGRectMake(6, 3, 136, 21)];

  [lblTitle setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]];
  [lblTitle setTextColor:[UIColor blackColor]];
  [lblTitle setTextAlignment:NSTextAlignmentLeft];
  [lblTitle setBackgroundColor:[UIColor clearColor]];
  [viewHeader addSubview:lblTitle];

  return viewHeader;

give it any particular height. and give it any text. make an Array for section Headers which will contain your years.