我不知道表格视图中所选行颜色没有变化的原因。
我创建了自定义单元格并将渐变颜色应用于单元格的背景,还编写了代码以使用选定的背景更改 bgcolor。问题是,如果我不使用渐变颜色,它工作得很好,但如果使用渐变颜色,它不会改变 bgcolor。
具体问题是什么??有什么解决办法吗??
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier=@"ViewProfileCell";
MyHomeViewCell *cell= [[MyHomeViewCell alloc] init];
cell=(MyHomeViewCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(!cell)
{
NSArray *nibofMyHomeCell=[[NSBundle mainBundle]loadNibNamed:@"MyHomeViewCell" owner:self options:Nil];
cell=[nibofMyHomeCell objectAtIndex:0];
}
UIView *v=[[UIView alloc]init];
v.layer.backgroundColor=[[UIColor colorWithRed:46.0/255.0f green:139.0/255.0f blue:87.0/255.0f alpha:1 ]CGColor];
cell.selectedBackgroundView=v;
CAGradientLayer *ViewGradient=[CAGradientLayer layer];
ViewGradient.frame=CGRectMake(0, 0, 320, 52);
ViewGradient.colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:27.0f / 255.0f green:48.0f / 255.0f blue:39.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:26.0f / 255.0f green:47.0f / 255.0f blue:38.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:25.0f / 255.0f green:44.0f / 255.0f blue:37.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:23.0f / 255.0f green:42.0f / 255.0f blue:35.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:22.0f / 255.0f green:41.0f / 255.0f blue:34.0f / 255.0f alpha:1.0f] CGColor],
(id)[[UIColor colorWithRed:22.0f / 255.0f green:40.0f / 255.0f blue:33.0f / 255.0f alpha:1.0f] CGColor],
nil];
[cell.layer insertSublayer:ViewGradient atIndex:0];
cell.layer.shadowColor = [[UIColor whiteColor] CGColor];
cell.layer.shadowOpacity=20.0f;
cell.layer.borderWidth=1.0f;
cell.layer.borderColor=[[UIColor colorWithRed:38.0f / 255.0f green:70.0f / 255.0f blue:58.0f / 255.0f alpha:1.0f] CGColor];
}