I am trying to implement one feature:
Image 1 show headers with titles. When you click on header 1,2,3,4 it will expand and shows tableview rows like shown in image 2.
What I want is that at header 0 view, I want to customize and wants to add an image and some text (see image 3).
How to achieve this feature, how can I can I customize tableview header using Objective-C?
I used below code but not showing any changes,
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string =[list objectAtIndex:section];
/* Section header is in 0th index... */
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
return view;
}
user the
viewForHeaderInSection
method . It returns a UIView. You could create your desired UIView() programatically. I assume you know how to do that.Now, in this method check the
indexPath.row
. IF its "0" then your ImageView Should return ...else return some other view such as a label with a certain text. Hope it helps.