Reputation: 2942
I have a unique situation.
I want to display custom header text for table header section which I am able to do but instead of custom header section solid color i want default header section frame gradient. (Please see attached image)
Here's what I am doing in viewForHeaderInSection
method:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *customSectionHeaderView;
UILabel *titleLabel;
customSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, tableView.frame.size.width, 24)];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, tableView.frame.size.width, 24)];
titleLabel.textAlignment = UITextAlignmentLeft;
[titleLabel setTextColor:[UIColor blackColor]];
[titleLabel setBackgroundColor:[UIColor clearColor]];
titleLabel.font = [UIFont boldSystemFontOfSize:15];
titleLabel.text = self.sortedPaths[section];
[customSectionHeaderView addSubview:titleLabel];
return customSectionHeaderView;
}
By removing
customSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, tableView.frame.size.width, 24)];
I am able to get the result but then i can not add subview to it and return a view.
How can I achieve that gradient effect?
Upvotes: 3
Views: 1514
Reputation: 535222
Why not use tableView:titleForHeaderInSection:
instead? This gets you exactly what you're talking about: the default header with your text substituted.
Or you could just draw your own gradient, of course. iOS has excellent gradient-drawing methods.
Upvotes: 1