Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-05-2010, 05:43 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 3
danbretl is on a distinguished road
Default UITableView custom section header

I am implementing custom section headers for a UITableView using the tableView:viewForHeaderInSection method. Everything is good except that a cell separator is still showing up above each section header. This does not look good. If you look closely at Apple's default section headers, they are actually one pixel taller than their set height (set in tableView:heightForHeaderInSection) and that extra pixel covers up the separator that would otherwise be displayed there. I am confident that there is something going on with Apple's default section header view creation that I am not mimicking in my own tableView:viewForHeaderInSection, but I cannot figure out what it is. If anyone has any insight or ideas, please let me know.

Code:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
		
	// create the parent view
	UIView * customSectionView = [[UIView alloc] initWithFrame:CGRectMake(0.0, -5, self.tableView.frame.size.width, [self tableView:tableView heightForHeaderInSection:section])];
	customSectionView.backgroundColor = [[UIColor colorWithRed:0.306 green:0.161 blue:0.047 alpha:1.000] colorWithAlphaComponent:0.9];
	
	// create the label
	UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, customSectionView.frame.size.height)];
	headerLabel.backgroundColor = [UIColor clearColor];
	headerLabel.opaque = NO;
	headerLabel.textColor = [UIColor whiteColor];
	headerLabel.highlightedTextColor = [UIColor whiteColor];
	headerLabel.font = [UIFont fontWithName:@"Georgia" size:14];
	headerLabel.text = @"Foo";
	
	// package and return
	[customSectionView addSubview:headerLabel];
	[headerLabel release];
	return [customSectionView autorelease];
	
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
	
	return 30.0;
	
}

Last edited by danbretl; 09-05-2010 at 05:49 AM.
danbretl is offline   Reply With Quote
Old 02-27-2012, 12:14 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 2
palian is on a distinguished road
Default Custom section header

Hello

Did you figure it out?

I was looking and trying to figure out how to make the section headers black with white text.

Chris
palian is offline   Reply With Quote
Old 02-27-2012, 12:32 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 149
Brix is on a distinguished road
Default

Code:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
        UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,320,10)] autorelease];
	label.backgroundColor = [UIColor blackColor];
	label.textColor = [UIColor whiteColor];
	label.text = @"Your Text Here";
	
	return label;
}
__________________
Praise be to God

Last edited by Brix; 02-27-2012 at 12:35 AM.
Brix is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, header, section, separator, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 338
10 members and 328 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, linkmx, nadav@webtview.com, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:49 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0