各种设计的颜色,渐变的颜色有的确实漂亮,用设计切图由于不同的机型的大小不同,不能跟其他切图完美匹配,只好是代码完成渐变色的了。 *渐变色简单实现 -(CAGradientLayer *)setChangColorWithView:(UIView *)view andColorStart:(UIColor *)startColor andEndColor:(UIColor *)endColor{ CAGradientLayer *gradLayer = [CAGradientLayer layer]; gradLayer.frame = view.bounds; gradLayer.colors = @[(__bridge id)startColor.CGColor,(__bridge id)endColor.CGColor]; gradLayer.startPoint = CGPointMake(0.0, 1.0); gradLayer.endPoint = CGPointMake(1.0, 1.0); return gradLayer; return nil; } ======= colors 渐变的颜色 locations 渐变颜色的分割点,以上的方法没有使用到,因为是一个平缓过渡的颜色 具体使用: startPoint&endPoint 颜色渐变的方向,范围在(0,0)与(1.0,1.0)之间,如(0,0)(1.0,0)代表水平方向渐变,(0,0)(0,1.0)代表竖直方向渐变===== 使用 -(void)buildStatusBarBG{ _statusBGView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUIWidth, kUIHeight)]; CAGradientLayer *layer = [self setChangColorWithView:_statusBGView andColorStart:[UIColor colorWithRed:0 green:172/255.0 blue:242/255.0 alpha:1.0] andEndColor:[UIColor colorWithRed:69/255.0 green:117/255.0 blue:241/255.0 alpha:1.0]]; _statusBGView.layer.sublayers = nil; [_statusBGView.layer addSublayer:layer]; [self.view addSubview:_statusBGView]; } 后来看到有人总结的比较全面,但是没有一一实现。先mark后实现。 http://www.jianshu.com/p/3e0e25fd9b85 |
|