UITableView - Highlighting Selected Cell [iOS]

20,845

Solution 1

Maybe it's because your sample code is setting:

artistLabel.highlightedTextColor = [UIColor clearColor];.

It will cause the artistLabel's text color become transparent when it's highlighted.

Of cause you can set your own color to your labels' highlightedTextColor property, for example:

[UIColor whiteColor]

Solution 2

UITableView Cell selected Color

Enjoy...

// Image
UIImage *selectionBackground = [UIImage imageNamed:@"g7.png"];
UIImageView *bgview=[[UIImageView alloc] initWithImage:selectionBackground];
cell.selectedBackgroundView=bgview;
[bgview release];

or

// Color
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor brownColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];

Solution 3

u can use ur own customization view to selection

here i have green color view.like this u can change whatever customization u want on that.

if (cell == nil) {

    cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero 
                                   reuseIdentifier: CellIdentifier] autorelease];


    UIView *selectionView = [[UIView alloc]initWithFrame:cell.bounds];

    [selectionView setBackgroundColor:[UIColor greenColor]];

    cell.selectedBackgroundView = selectionView;


    [selectionView release];

}
Share:
20,845
Paul Morris
Author by

Paul Morris

Updated on July 05, 2022

Comments

  • Paul Morris
    Paul Morris almost 2 years

    I have created a UITableView with customising a TableCell, generally following this tutorial;

    http://www.theappcodeblog.com/?p=353

    I have customised it to my needs and it looks fantastic. However, when I select a row it highlights that row by changing the entire thing blue. This highlight covers the entire cell and overrides the content, effectively making a big blue box which looks nasty. I have tried the alternate highlight options of

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    

    Obviously if selected as gray, the same behaviour happens but with a gray ugly box. 'None' is the desirable option at the minute, but doesn't provide a good experience to my users as i'd like to give some indication that they have selected that row.

    Can anyone suggest a way to show that the row is highligted, but still show the text underneath? Semi opacity?

    Thanks

  • Paul Morris
    Paul Morris over 12 years
    What an absolute idiot I am, thank you. Simple answer, that worked perfectly. Thanks
  • xuzhe
    xuzhe over 12 years
    You are welcome. If you think this answer is useful, a vote up and select it as correct answer will be very appreciated.
  • Paul Morris
    Paul Morris over 12 years
    I always do. I have 100% fore very question I ask. Thanks again.
  • xuzhe
    xuzhe over 12 years
    :) Thank you, too. It's hard to keep that rate 100%, That's pretty incredible.
  • Nikolay Shubenkov
    Nikolay Shubenkov over 10 years
    I also would recommend to call [cell setSelectionStyle: UITableViewCellSelectionStyleNone] which prevent cell from white rectangle on it perimeter when it is selected.