设置渐变色

CAGradientLayer

官方说明:
The gradient layer draws a color gradient over its background color,filling the shape of the layer (i.e. including rounded corners).
具体代码:


UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 113)];
[self.view addSubview:topView];
topView.backgroundColor = [UIColor lightGrayColor];
// 添加颜色渐变效果
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
// colors :由哪几种颜色进行渐变
gradientLayer.colors = 
@[(__bridge id)[UIColor hexStringToColor:@"FFCA37"].CGColor,
(__bridge id)[UIColor hexStringToColor:@"FFb142"].CGColor,
(__bridge id)[UIColor hexStringToColor:@"F7981F"].CGColor];
//locations:颜色开始渐变的位置,取值区间是[0,1]
gradientLayer.locations = @[@0.2,@0.5,@0.8];
// 
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
// 为gradientLayer设置frame
gradientLayer.frame = topView.bounds;
[topView.layer addSublayer:gradientLayer];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //为颜色设置渐变效果 UIView *view = [[UIView alloc] initWithFrame:...
    蚂蚁也疯狂阅读 270评论 0 0
  • 从秦始皇开始,中国有了“皇帝”的称谓,据说来自“三皇五帝”。始皇自称“始”,希望秦自此传到二世、三世……直至万世。...
    haywirehouse阅读 451评论 0 0
  • 我的姥姥是一位漂亮自信的女人,年轻时随团队经常外出表演。 后来不知为何病了,动了手术,好了后有一条腿已经不太灵活了...
    雯慧仙阅读 270评论 0 0
  • 其实,我并不清楚,自己为什么喜欢写东西,只是觉得有时候我需要去写,去表达,去跟另一个世界的自己对话,我能从中获取让...
    南州小姐阅读 324评论 1 2
  • 腾讯董事长马化腾所讲到: 人们不缺乏分享的欲望,这得益于互联网所带来的技术革命,用通俗的话来说,就是“天时”、“地...
    还一直在路上阅读 835评论 0 3