CalenderCollectionCell.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // CalenderCollectionCell.m
  3. // YZCCalender
  4. //
  5. // Created by Jason on 2018/1/17.
  6. // Copyright © 2018年 jason. All rights reserved.
  7. //
  8. #import "CalenderCollectionCell.h"
  9. #import "CalenderModel.h"
  10. #import "UIColor+Extension.h"
  11. @interface CalenderCollectionCell()
  12. @property (nonatomic, strong) UILabel *numberLabel;
  13. @property (nonatomic, strong) UILabel *toDayL;
  14. @end
  15. @implementation CalenderCollectionCell
  16. #pragma mark - lazy
  17. - (instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self.contentView addSubview:self.numberLabel];
  22. [self.contentView addSubview:self.toDayL];
  23. [self.toDayL mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.top.mas_equalTo(self.numberLabel.mas_bottom).offset(5);
  25. make.centerX.mas_equalTo(self.contentView);
  26. }];
  27. }
  28. return self;
  29. }
  30. - (UILabel *)numberLabel {
  31. if (_numberLabel == nil) {
  32. _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)];
  33. _numberLabel.textAlignment = NSTextAlignmentCenter;
  34. _numberLabel.font = [UIFont systemFontOfSize:16];
  35. _numberLabel.textColor = [UIColor colorWithHexString:@"#0A0A0A"];
  36. }
  37. return _numberLabel;
  38. }
  39. - (UILabel *)toDayL {
  40. if (_toDayL == nil) {
  41. _toDayL = [[UILabel alloc] init];
  42. _toDayL.textAlignment = NSTextAlignmentCenter;
  43. _toDayL.font = [UIFont systemFontOfSize:10];
  44. _toDayL.textColor = UIColorHex(#3979D3);
  45. _toDayL.text = @"今天";
  46. }
  47. return _toDayL;
  48. }
  49. -(void)setModel:(CalenderModel *)model {
  50. _model = model;
  51. self.toDayL.hidden = !model.isToday;
  52. self.numberLabel.text = model.day;
  53. self.numberLabel.textColor = model.isUse ? [UIColor colorWithHexString:@"#0A0A0A"] : [UIColor grayColor];
  54. if (model.isSelected) {
  55. self.numberLabel.layer.cornerRadius = self.numberLabel.frame.size.width * 0.5;
  56. self.numberLabel.layer.masksToBounds = YES;
  57. self.numberLabel.backgroundColor = [UIColor colorWithHexString:@"#3979D3"];
  58. self.numberLabel.textColor = [UIColor whiteColor];
  59. self.numberLabel.backgroundColor = [UIColor colorWithHexString:@"#3979D3"];
  60. [self addAnimaiton];
  61. }else{
  62. self.numberLabel.layer.cornerRadius = 0;
  63. self.numberLabel.layer.masksToBounds = YES;
  64. self.numberLabel.backgroundColor = [UIColor clearColor];
  65. }
  66. }
  67. -(void)addAnimaiton{
  68. CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
  69. anim.values = @[@0.6,@1.2,@1.0];
  70. anim.keyPath = @"transform.scale"; // transform.scale 表示长和宽都缩放
  71. anim.calculationMode = kCAAnimationPaced;
  72. anim.duration = 0.25;
  73. [self.numberLabel.layer addAnimation:anim forKey:nil];
  74. }
  75. @end