简体   繁体   中英

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

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]

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

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM