在我的应用程序中,我使用CAGradientLayer设置我的单元格的背景,这样:
retValue = [tableView dequeueReusableCellWithIdentifier:@"Cells" forIndexPath:indexPath]; UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor blueColor]; bgColorView.layer.masksToBounds = YES; id startColor = (id)[[UIColor colorWithWhite:0.75 alpha:1] CGColor]; id endColor = (id)[[UIColor blueColor] CGColor]; CAGradientLayer* gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = retValue.contentView.bounds; gradientLayer.colors = @[startColor,startColor,endColor,endColor]; gradientLayer.locations = @[[NSNumber numberWithFloat:0],[NSNumber numberWithFloat:0.95],[NSNumber numberWithFloat:1]]; [gradientLayer setStartPoint:CGPointMake(0,0.5)]; [gradientLayer setEndPoint:CGPointMake(1,0.5)]; [bgColorView.layer addSublayer:gradientLayer]; retValue.selectedBackgroundView = bgColorView;
(这段代码在里面 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath 原文链接:https://www.f2er.com/iOS/337637.html