1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // HomeQualityMusicCollectionCell.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2022/9/13.
- //
- #import "HomeQualityMusicCollectionCell.h"
- @interface HomeQualityMusicCollectionCell ()
- @property (weak, nonatomic) IBOutlet UIView *containerView;
- @property (nonatomic, copy) QualityMusicDetailBlock callback;
- @end
- @implementation HomeQualityMusicCollectionCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
-
- CAGradientLayer *layer = [self createGradientLayerFromColor:HexRGB(0xFFF4EC) startPoint:CGPointMake(0.5, 0) endColor:HexRGB(0xFFFDFB) endPoint:CGPointMake(0.5, 1) bounds:CGRectMake(0, 0, KPortraitWidth * 0.83, 320)];
- layer.cornerRadius = 10.0f;
- layer.masksToBounds = YES;
- [self.containerView.layer addSublayer:layer];
- }
- - (CAGradientLayer *)createGradientLayerFromColor:(UIColor *)fromColor startPoint:(CGPoint)startPoint endColor:(UIColor *)endColor endPoint:(CGPoint)endPoint bounds:(CGRect)bounds {
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
- gradientLayer.colors = @[(__bridge id)fromColor.CGColor, (__bridge id)endColor.CGColor];
- gradientLayer.startPoint = startPoint;
- gradientLayer.endPoint = endPoint;
- gradientLayer.frame = bounds;
- gradientLayer.locations = @[@(0),@(1.0f)];
- return gradientLayer;
- }
- - (void)configWithSourceArray:(NSMutableArray *)songArray callback:(QualityMusicDetailBlock)callback {
- if (callback) {
- self.callback = callback;
- }
- [self.containerView removeAllSubViews];
- CGFloat width = KPortraitWidth * 0.83;
- for (NSInteger i = 0; i < songArray.count; i++) {
- // 添加按钮
- HomeQualityMusicCellView *cell = [HomeQualityMusicCellView shareInstance];
- cell.frame = CGRectMake(0, 80 * i, width, 80);
- BOOL hideLineView = i == songArray.count - 1 ? YES : NO;
- MJWeakSelf;
- [cell configWithMusicModel:songArray[i] hiddenLineView:hideLineView callback:^(NSString * _Nonnull songId) {
- if (weakSelf.callback) {
- weakSelf.callback(songId);
- }
- }];
- [self.containerView addSubview:cell];
- }
-
- }
- @end
|