gpt4 book ai didi

ios - 使特定的 UITableViewCells 具有不同的背景颜色

转载 作者:行者123 更新时间:2023-11-28 19:55:55 25 4
gpt4 key购买 nike

在我的表格 View 中,我希望前两项具有浅绿色背景色。我之前研究过这个主题,并且正在使用这些答案中提供的代码,但它对我不起作用。这是我的代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
cell.backgroundColor = [UIColor colorWithRed:144 green:238 blue:144 alpha:1];
}

else if (indexPath.row == 1)
{
cell.backgroundColor = [UIColor colorWithRed:144 green:238 blue:144 alpha:1];
}
}

我做错了什么?我怎样才能改进此代码以提高效率和效果?

最佳答案

尝试

cell.backgroundColor = [UIColor colorWithRed:144.0/255.0 green:238/255.0 blue:144/255.0 alpha:1];

组件的值定义为 0.0 到 1.0 之间的 float

+ (UIColor *)colorWithRed:(CGFloat)red
green:(CGFloat)green
blue:(CGFloat)blue
alpha:(CGFloat)alpha

Parameters

red
The red component of the color object, specified as a value from 0.0 to 1.0.

green
The green component of the color object, specified as a value from 0.0 to 1.0.

blue
The blue component of the color object, specified as a value from 0.0 to 1.0. alpha The opacity value of the color object, specified as a value from 0.0 to 1.0.

https://developer.apple.com/library/ios/documentation/uikit/reference/UIColor_Class/index.html#//apple_ref/occ/clm/UIColor/colorWithRed:green:blue:alpha :

关于ios - 使特定的 UITableViewCells 具有不同的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26416348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com