开发者

UITableView - Highlighting Selected Cell [iOS]

开发者 https://www.devze.com 2023-04-01 13:25 出处:网络
I have created a UITableView with customising a TableCell, generally following this tutorial; http://www.theappcodeblog.com/?p=353

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 b开发者_如何学JAVAig 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];

}
0

精彩评论

暂无评论...
验证码 换一张
取 消