views:

200

answers:

2

i have a uitableview cell added some labels something like this

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *CellIdentifier = @"Cell"; 

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

     UIImage* myImage = [UIImage imageNamed:@"AccessoryForDealsMain.png"];
     UIImageView *MyimageView = [[UIImageView alloc] initWithImage:myImage];
     MyimageView.contentMode=UIViewContentModeScaleToFill;
     cell.accessoryView=MyimageView;
     [MyimageView release];

     UILabel *BluePatti = [[UILabel alloc] init];
     BluePatti.frame=CGRectMake(0,0,4,44);
     BluePatti.backgroundColor = BLUEPATTI;//[UIColor blueColor];
     UILabel *BlackLine = [[UILabel alloc] init];
     BlackLine.frame=CGRectMake(3,0,1, 45);
     BlackLine.backgroundColor = BLACK_LINE;
     [BluePatti addSubview:BlackLine];
     [BlackLine release];

     [cell.contentView addSubview:BluePatti];
     [BluePatti release];

     UILabel *Seperator = [[UILabel alloc] initWithFrame:CGRectZero];
     Seperator.backgroundColor = [UIColor colorWithRed:234/256.0 green:234/256.0 blue:234/256.0 alpha:1.0]; //[UIColor lightGrayColor];
     Seperator.frame = CGRectMake(4,43,316,1);
     [cell.contentView addSubview:Seperator];
     [Seperator release];
}
if(indexPath.section==5)
{
    cell.textLabel.text=[self.GenderCellData objectAtIndex:indexPath.row];
    cell.textLabel.textColor=CELL_TEXT_COLOR;
    cell.textLabel.font=CELL_FONT;
}
else
{
    cell.textLabel.text=@"Cells";
    cell.textLabel.font=CELL_FONT;
}
return cell;
}

now when i touch cell it shows blue selection above all subviews.How do i change selection frame and colour?

A: 

These are the options that Apple is giving you for the tableView.selectionStyle property: Grey, Blue, None:

typedef enum {
   UITableViewCellSelectionStyleNone,
   UITableViewCellSelectionStyleBlue,
   UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;

Of course, UITableViewCell is a UIResponder so if you want to do something completely custom you can implement you own handling of touches

– touchesBegan:withEvent: 
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
Dimitris
A: 

You can create a custom selectedBackgroundView in UITableViewCell that has your own frame and color. This will be shown when the cell is selected instead of the default blue background.

For example:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 30, 40)];
view.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = view;
[view release];
Adam Woś
but it's shown on complete cell.i have used this.I just want to show selection on limited frame but still no success
Rahul Vyas