NNikN
NNikN

Reputation: 3860

TableHeaderView and headers of sections

I am able to add view to the tableHeaderView using the below mentioned code:-

MyView *view=[[MyView alloc] init];
.....
tableView.tableHeaderView=view;

But, I am unable to add spacing between this view and headers of first section.

Upvotes: 0

Views: 1200

Answers (2)

Ash Furrow
Ash Furrow

Reputation: 12421

You can encapsulate your main view like this:

MyView *view=[[MyView alloc] init];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height + 5)]; //5 pixel gap
view.frame = CGRectMake(0, 5, view.frame.size.width, view.frame.size.height);
[headerView addSubview:view];
.....
tableView.tableHeaderView=headerView;

I've created a new headerView, added the view to that view, and then set the tableHeaderView appropriately.

Upvotes: 1

Yatin Sarbalia
Yatin Sarbalia

Reputation: 209

One solution that i can think is that you create a 'parent' view with height = (view.frame.height + )

Then add 'view' as a subview of 'parent' view and set 'parent' view as your table header.

Upvotes: 0

Related Questions