渐变
再很多场合下,需要一个渐变的效果,其实实现起来也不难。
需要用到一个类CAGradientLayer。
UIView *view = [[UIView alloc] init];
CAGradientLayer *layer = [CAGradientLayer layer];
layer.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)[[UIColor blackColor] colorWithAlphaComponent:0.3].CGColor];
layer.startPoint = CGPointMake(0, 1);
layer.endPoint = CGPointMake(0, 0);
layer.frame = CGRectMake(0, 0, DivceWidth, 10);
layer.locations = @[@(0.6f) ,@(1.0f)];
[view.layer addSublayer:layer];
有错误请欢迎指正!
本文介绍如何使用 CAGradientLayer 类在 iOS 开发中实现渐变效果。通过设置颜色、起始点、结束点等属性,可以轻松创建出美观的渐变背景。
3266

被折叠的 条评论
为什么被折叠?



