Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - Highlighting Selected Cell [iOS]

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

like image 863
Paul Morris Avatar asked Aug 29 '11 08:08

Paul Morris


3 Answers

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]

like image 59
xuzhe Avatar answered Nov 01 '22 03:11

xuzhe


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];
like image 28
iSavaDevRU Avatar answered Nov 01 '22 04:11

iSavaDevRU


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];

}
like image 20
Vijay-Apple-Dev.blogspot.com Avatar answered Nov 01 '22 03:11

Vijay-Apple-Dev.blogspot.com