iOS 背景图像上的纯文本和低 Alpha 单元格背景

问题描述 投票:0回答:1

如何让单元格中的文本显示为纯文本,同时仍然淡化单元格背景,以便我可以看到后面的图像?

我的 ViewController 中有以下内容: `

- (void)viewDidLoad {
    // Used to see the background image
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage    imageNamed:@"background.png"]];
    self.tableView.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
}

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.alpha=0.5; 
    cell.textLabel.alpha=1.0; 
}

结果显示在图像中,通过文本和单元格背景可以看到背景图像。我只想透过单元格背景查看图像并让文本保持不变。

有没有办法将文本的 alpha 设置为 1.0,而背景为 0.5?

app screenshot

ios objective-c uitableview background alpha
1个回答
0
投票

您可以将其放入

cellForRowAtIndexPath
willDisplayCell
:

cell.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];

输出:

像平常一样设置标签文本颜色(在

cellForRowAtIndexPath
中),然后调整
colorWithAlphaComponent:0.5
以满足您的需要。

© www.soinside.com 2019 - 2024. All rights reserved.