// // CalenderCollectionCell.m // YZCCalender // // Created by Jason on 2018/1/17. // Copyright © 2018年 jason. All rights reserved. // #import "CalenderCollectionCell.h" #import "CalenderModel.h" #import "UIColor+Extension.h" @interface CalenderCollectionCell() @property (nonatomic, strong) UILabel *numberLabel; @property (nonatomic, strong) UILabel *toDayL; @end @implementation CalenderCollectionCell #pragma mark - lazy - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self.contentView addSubview:self.numberLabel]; [self.contentView addSubview:self.toDayL]; [self.toDayL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.numberLabel.mas_bottom).offset(5); make.centerX.mas_equalTo(self.contentView); }]; } return self; } - (UILabel *)numberLabel { if (_numberLabel == nil) { _numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width * 0.5 - 30 * 0.5, self.frame.size.height * 0.5 - 30 * 0.5, 30, 30)]; _numberLabel.textAlignment = NSTextAlignmentCenter; _numberLabel.font = [UIFont systemFontOfSize:16]; _numberLabel.textColor = [UIColor colorWithHexString:@"#0A0A0A"]; } return _numberLabel; } - (UILabel *)toDayL { if (_toDayL == nil) { _toDayL = [[UILabel alloc] init]; _toDayL.textAlignment = NSTextAlignmentCenter; _toDayL.font = [UIFont systemFontOfSize:10]; _toDayL.textColor = UIColorHex(#3979D3); _toDayL.text = @"今天"; } return _toDayL; } -(void)setModel:(CalenderModel *)model { _model = model; self.toDayL.hidden = !model.isToday; self.numberLabel.text = model.day; self.numberLabel.textColor = model.isUse ? [UIColor colorWithHexString:@"#0A0A0A"] : [UIColor grayColor]; if (model.isSelected) { self.numberLabel.layer.cornerRadius = self.numberLabel.frame.size.width * 0.5; self.numberLabel.layer.masksToBounds = YES; self.numberLabel.backgroundColor = [UIColor colorWithHexString:@"#3979D3"]; self.numberLabel.textColor = [UIColor whiteColor]; self.numberLabel.backgroundColor = [UIColor colorWithHexString:@"#3979D3"]; [self addAnimaiton]; }else{ self.numberLabel.layer.cornerRadius = 0; self.numberLabel.layer.masksToBounds = YES; self.numberLabel.backgroundColor = [UIColor clearColor]; } } -(void)addAnimaiton{ CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; anim.values = @[@0.6,@1.2,@1.0]; anim.keyPath = @"transform.scale"; // transform.scale 表示长和宽都缩放 anim.calculationMode = kCAAnimationPaced; anim.duration = 0.25; [self.numberLabel.layer addAnimation:anim forKey:nil]; } @end