// // YOUPAIGradualButton.m // MSYOUPAI // // Created by admin on 2022/3/10. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAIGradualButton.h" #import "YYKit.h" @implementation YOUPAIGradualButton - (instancetype)initWithFrame:(CGRect)frame{ if(self == [super initWithFrame:frame]){ [self.layer addSublayer:self.gradientLayer]; @weakify(self) [self addObserverBlockForKeyPath:@"bounds" block:^(id _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) { @strongify(self) self.gradientLayer.frame = self.bounds; [self ms_radius:self.bounds.size.height/2]; }]; } return self; } -(CAGradientLayer *)gradientLayer{ if(_gradientLayer == nil){ _gradientLayer = [CAGradientLayer layer]; _gradientLayer.locations = @[@(0), @(1.0f)]; _gradientLayer.startPoint = CGPointMake(0.06, 0); _gradientLayer.endPoint = CGPointMake(0.95, 0.95); _gradientLayer.colors = @[(__bridge id)LZBFB6FFColor.CGColor, (__bridge id)LZ7C69FEColor.CGColor]; } return _gradientLayer; } -(void)dealloc{ [self removeObserverBlocks]; } @end