// // YViewGradient.m // AoleYou20170907 // // Created by XY IOS on 2018/4/25. // Copyright © 2018年 -陈诗友. All rights reserved. // #import "YViewGradient.h" @implementation YViewGradient /** button gradient @param viewid button */ +(void)changeAlphaWithviewID:(UIButton *)viewid{ CAGradientLayer *_gradLayer = [CAGradientLayer layer]; NSArray *colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithWhite:0 alpha:1] CGColor], (id)[[UIColor colorWithWhite:0 alpha:0.8] CGColor], (id)[[UIColor colorWithWhite:0 alpha:0.6] CGColor], nil]; [_gradLayer setColors:colors]; // Gradient start and end point, point represents the vector [_gradLayer setStartPoint:CGPointMake( 1.0f , 0.0f )]; [_gradLayer setEndPoint:CGPointMake(0.0f, 0.0f)]; [_gradLayer setFrame:viewid.bounds]; [viewid.layer setMask:_gradLayer]; } @end