iOS 7.0中的水平CAGradientLayer

前端之家收集整理的这篇文章主要介绍了iOS 7.0中的水平CAGradientLayer前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我使用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

猜你在找的iOS相关文章