Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem in customize cell selection Style in UITableView in iPhone

In my application ,I am using Grouped style for TableView. In that I want to customize the cell selection Style.I want that selection Style to be red.

I am using the below code for that:

UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor];

[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];

By using the above code. I have a problem.Since I have taken grouped Style table , in the selection of first and last rows, the selection is appear with sharp edged rectangle instead of appeaing round Corners.

Can Anyone Help me in this. Thanks in Advance.

like image 780
Monish Kumar Avatar asked Jun 25 '11 08:06

Monish Kumar


2 Answers

Try this ,

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

    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectedCellBackground.png"]] autorelease];
    }

    // Cell configuration takes place here
}
like image 102
Rahul Nair Avatar answered Nov 07 '22 04:11

Rahul Nair


add QuartzCore framework. and import QuartzCore/QuartzCore.h framework in .m file. and after that add following code in cellForRowAtIndexPath Method.

UIImageView *imv = [[UIImageView alloc]init];
imv.backgroundColor=[UIColor redColor];
[cell setSelectedBackgroundView:imv];
CALayer *layer = imv.layer;
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0];
[imv release];
like image 30
Vibhooti Avatar answered Nov 07 '22 05:11

Vibhooti