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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-05-2010, 06:48 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 83
Default Table View Cells color

How can I set the cell color of my cell ?

I am doing:

Code:
[[cell contentView] setBackgroundColor:[UIColor blackColor]];
But it doesn't set the color on the middle zone...

I've tried setting background color for the textLabel etc but can't seem to get what I want...

djp_phillips is offline   Reply With Quote
Old 03-05-2010, 07:35 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 3
Default Here is a good template that i use for tableviews

Code:
// replace your cellForRowAtIndexPath with this one
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
	
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
	}
	cell = [self getCellContentView:CellIdentifier:indexPath.row];    
	
    return cell;
}

// add this function to your code
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier:(int)cellIndex {
	
// make sure your height below matches your cell height set
// or your cells will not be lined up with the color
	CGRect CellFrame = CGRectMake(0, 0, 320, 60);
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
	
	// put a UIView underneath for coloring
	UIView * view = [[UIView alloc] initWithFrame:CellFrame];
	
	if ( cellIndex%2 == 0 ){
// edit your cell color below
		view.backgroundColor = [UIColor whiteColor];
	}else{
// edit cell color 2 below
		view.backgroundColor = [UIColor colorWithRed:.238 green:.238 blue:0.238 alpha:.10];
	}
	[cell.contentView addSubview:view];
	[view release];
	
		
	return cell;
}


///// this template will allow you to color every other cell a different color if desired replace your cellForRowAtIndexPath ... and add the cellIdentifier function
Louis002 is offline   Reply With Quote
Old 03-06-2010, 06:58 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 83
Default

Hi, thanks, that solution wasn't really what I needed, I wanted to make the entire list of cells black, not just color the one with content. Is that possible ?

Also I found a shorter way to color a cell:



The result at the moment is:



How could I color the other rows ?
djp_phillips is offline   Reply With Quote
Reply

Bookmarks

Tags
background, cell, color

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: 348
20 members and 328 guests
ADY, Dani77, e2applets, Herbie, JasonR, keeshux, linkmx, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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