Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-20-2008, 01:41 PM   #9 (permalink)
Jume
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 254
Send a message via Skype™ to Jume
Default

Maybe I can help.. this screen is from myApp. If this is something similar you want to achieve than here how I do it.



1) table view controller file
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   //create my own cell view
  ChannelTableViewCell *cell = (ChannelTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ChannelTableViewCell"];

   //create my view for cell bacground (just draw gradient)
   ChannelTableCellBackgroundView *cellBgView = [[ChannelTableCellBackgroundView alloc] initWithFrame:CGRectZero];
   cell.backgroundView = cellBgView;
   [cellBgView release];

   // .... other code continues ...
}

2. custom cell view code (subclass of UITableViewCell, this layouts labels images for tile view)

Code:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
	
    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
		channel = nil;
		channelTileView = nil;
		labelView = nil;		
		
		// create the channelTileView and the labelView
		// both of these will be laid out again by the layoutSubviews method
		ChannelTileView *tileView = [[ChannelTileView alloc] initWithFrame:CGRectZero];
		self.channelTileView = tileView;
		[self.contentView addSubview:tileView];
		[tileView release];
		
		UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
		// set the label view to have a clear background and a 20 point font
		label.backgroundColor = [UIColor clearColor];
		label.font = [UIFont systemFontOfSize:18];
		self.labelView = label;
		[self.contentView addSubview:label];
		[label release];
		
		
		// add both the label and channelTile to the TableViewCell view
    }
    return self;
}

- (void)layoutSubviews {
	[super layoutSubviews];

	// determine the content rect for the cell. This will change depending on the
	// style of table (grouped vs plain)
	CGRect contentRect = self.contentView.bounds;
	
	// position the image tile in the content rect.
	CGRect channelTileRect = self.contentView.bounds;
	channelTileRect.size = [ChannelTileView preferredViewSize];
	channelTileRect = CGRectOffset(channelTileRect,10,9);
	channelTileView.frame = channelTileRect;
	
	// position the channel name in the content rect
	CGRect labelRect = contentRect;
	labelRect.origin.x = labelRect.origin.x+80;
	labelRect.origin.y = labelRect.origin.y-1;
	labelView.frame = labelRect;	
}

3. and the code of custom background view (subclass of UIView, this just draws a simple gradient)

Code:
- (id)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		// Initialization code
	}
	return self;
}


- (void)drawRect:(CGRect)rect {
	CGContextRef myContext = UIGraphicsGetCurrentContext();
	CGGradientRef myGradient;
	CGColorSpaceRef myColorspace;

	size_t num_locations = 2;
	CGFloat locations[2] = { 0.0, 1.0};
	CGFloat components[8] = {  0.92, 0.92, 0.92, 1.0,
								0.82, 0.82, 0.82, 1.0 };
	
		
	myColorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
	myGradient = CGGradientCreateWithColorComponents (myColorspace, components,
													  locations, num_locations);

	CGPoint myStartPoint, myEndPoint;
	myStartPoint.x = 0.0;
	myStartPoint.y = 0.0;
	myEndPoint.x = 1.0;
	myEndPoint.y = 100.0;
	CGContextDrawLinearGradient (myContext, myGradient, myStartPoint, myEndPoint, 0);	
}

Hope you can help ourself with this. It's pretty straight forward all you need to do is:
- subclass UITableViewCell
- set cell.backgroundView to your custom view you want for cell background;

Last edited by Jume; 08-20-2008 at 01:43 PM.
Jume is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,324
Threads: 39,122
Posts: 171,530
Top Poster: smasher (2,577)
Welcome to our newest member, tungbh
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:22 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.