我有一个 UITableView
。我在那个 Tableview 中有 4 个单元格。
我的 Tableview alpha 值为 0.8。
但我的要求是我希望前 3 个单元格的 alpha 值是 0.8,第 4 个单元格的 alpha 值是 1.0。
那么如何根据单元格设置这些alpha值呢?
请帮帮我。我最近 2 天遇到了这个问题。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
NSString *simpleTableIdentifier = [NSString stringWithFormat:@"%@%d",@"Cell",indexPath.row];
if (indexPath.row == 0)
{
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
cell.alpha = 0.8;
}
}
else if (indexPath.row == 1)
{
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
cell.alpha = 0.8;
}
}
else if(indexPath.row == 2)
{
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
cell.alpha = 0.8;
}
}
else if (indexPath.row == 3)
{
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
cell.alpha = 1.0;
}
}
return cell;
}
最佳答案
我希望这一行代码能解决您的问题
cell.contentView.alpha = 0.8
关于ios - 如何设置 Tableview 单元格的 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26093563/