当前位置: 动力学知识库 > 问答 > 编程问答 >

uitableview - How to change opacity of Table Cell on tap in Ios

问题描述:

I want to change the opacity of Table cell when it is tap and retain its opacity back when tap is released. I have set selection style property none.

网友答案:

I didn't understand your question. But if you want to change the cell background color and opacity, you have to set alpha

cell.backgroundColor = [UIColor colorWithRed:0. green:0.39 blue:0.106 alpha:0.]

cell tap event

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

if you want to change the cell color when you tap you can use this method.

网友答案:

Use this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];

    cell.backgroundColor = [UIColor colorWithRed:x green:y blue:z alpha:alphaValue];
    //Or use:
    cell.contentView.backgroundColor = [UIColor colorWithRed:x green:y blue:z alpha:alphaValue];
}
网友答案:

use this :

//change opacity when select row
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.contentView.layer.opacity = 0.4;
    return indexPath;
}

//the opacity back when deselect row
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.contentView.layer.opacity = 1;
    return indexPath;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: