I spent a few hours coding a UITableViewCell to look and function as an iphone button in a grouped UITableView and thought others might appreciate the code.
(The button look isn't perfect, I'll probably spend some more time getting the "light" just right on it.)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {/* other stuff */
static NSString *DoneButtonCellIdentifier = @"DoneButtonCell";
if (cell == nil) {
// Create a cell to display an emotion.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DoneButtonCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
//creates the button look
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 0, 280, 43)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
[gradient setCornerRadius:9.0f];
[gradient setMasksToBounds:YES];
[gradient setBorderWidth:0.8f];
[gradient setBorderColor:[[UIColor darkGrayColor] CGColor]];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor greenColor] CGColor], (id)[[UIColor colorWithRed:.05 green:.65 blue:.05 alpha:1] CGColor],(id)[[UIColor colorWithRed:.05 green:.65 blue:.05 alpha:1] CGColor], (id)[[UIColor colorWithRed:.05 green:.45 blue:.05 alpha:1] CGColor], nil];
gradient.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.10],[NSNumber numberWithFloat:0.49],[NSNumber numberWithFloat:0.51],[NSNumber numberWithFloat:1.0]];
[view.layer insertSublayer:gradient atIndex:0];
[cell.contentView addSubview:view];
//"button" label
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake( 10, 0.0, 280, 43)] autorelease];
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:20.0];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor lightGrayColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
label.backgroundColor = [UIColor clearColor];
label.text=@"Done";
[cell.contentView addSubview: label];
//makes cell transparent
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
return cell;

Recent Comments