DayCollectionViewCell.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // DayCollectionViewCell.m
  3. // BJTResearch
  4. //
  5. // Created by yunlong on 17/5/11.
  6. // Copyright © 2017年 yunlong. All rights reserved.
  7. //
  8. #import "DayCollectionViewCell.h"
  9. #import "MonthModel.h"
  10. #import "ADHTuanCan-Swift.h"
  11. #define NormalColor [UIColor whiteColor]
  12. #define StartAndEndColor [UIColor colorWithRed:198/255.0 green:34/255.0 blue:35/255.0 alpha:1.0]
  13. #define SelectedColor [UIColor colorWithRed:198/255.0 green:34/255.0 blue:35/255.0 alpha:1.0]
  14. @interface DayCollectionViewCell ()
  15. @property(nonatomic,strong) UILabel *gregorianCalendarLabel;
  16. @property(nonatomic,strong) UILabel *lunarCalendarLabel;
  17. @end
  18. @implementation DayCollectionViewCell
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. self.backgroundColor = [UIColor whiteColor];
  24. self.gregorianCalendarLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height/2)];
  25. self.gregorianCalendarLabel.textAlignment = NSTextAlignmentCenter;
  26. self.gregorianCalendarLabel.font = [UIFont systemFontOfSize:12];
  27. self.gregorianCalendarLabel.textColor = [UIColor blackColor];
  28. self.gregorianCalendarLabel.backgroundColor = [UIColor clearColor];
  29. [self.contentView addSubview:self.gregorianCalendarLabel];
  30. self.lunarCalendarLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.self.bounds.size.height/2, self.bounds.size.width, self.bounds.size.height/2)];
  31. self.lunarCalendarLabel.textAlignment = NSTextAlignmentCenter;
  32. self.lunarCalendarLabel.font = [UIFont systemFontOfSize:12];
  33. self.lunarCalendarLabel.textColor = [UIColor blackColor];
  34. self.lunarCalendarLabel.backgroundColor = [UIColor clearColor];
  35. [self.contentView addSubview:self.lunarCalendarLabel];
  36. }
  37. return self;
  38. }
  39. -(void)setModel:(DayModel *)model{
  40. _model = model;
  41. if (model == nil) {
  42. self.gregorianCalendarLabel.text = @"";
  43. self.lunarCalendarLabel.text = @"";
  44. self.backgroundColor = NormalColor;
  45. }else{
  46. // if (model.isToday) {//是今天
  47. self.gregorianCalendarLabel.text = [NSString stringWithFormat:@"%02ld",model.day];
  48. NSString *string = [LanguagesUtil createTextByCtext:[NSString stringWithFormat:@"第%D天",model.Daysort] Etext:[NSString stringWithFormat:@"the%Dday",model.Daysort]];
  49. self.lunarCalendarLabel.text = string;
  50. if (model.Daysort > 0){
  51. self.lunarCalendarLabel.text = string;
  52. }else{
  53. self.lunarCalendarLabel.text = @"";
  54. }
  55. self.lunarCalendarLabel.textColor = [UIColor blackColor];
  56. self.gregorianCalendarLabel.textColor = [UIColor blackColor];
  57. self.layer.cornerRadius = 0;
  58. if (model.isStatePast) {
  59. self.userInteractionEnabled = NO;
  60. self.lunarCalendarLabel.textColor = [UIColor grayColor];
  61. self.gregorianCalendarLabel.textColor = [UIColor grayColor];
  62. }else{
  63. self.userInteractionEnabled = YES;
  64. self.lunarCalendarLabel.textColor = [UIColor blackColor];
  65. self.gregorianCalendarLabel.textColor = [UIColor blackColor];
  66. }
  67. switch (model.state) {
  68. case DayModelStateNormal:{
  69. self.backgroundColor = NormalColor;
  70. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(0, 0)];
  71. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  72. maskLayer.frame = self.bounds;
  73. maskLayer.path = maskPath.CGPath;
  74. self.layer.mask = maskLayer;
  75. break;
  76. }
  77. case DayModelStateStart:{
  78. self.backgroundColor = StartAndEndColor;
  79. self.lunarCalendarLabel.textColor = [UIColor whiteColor];
  80. // self.gregorianCalendarLabel.text = @"入住";
  81. self.gregorianCalendarLabel.textColor = [UIColor whiteColor];
  82. // self.layer.cornerRadius = 30;
  83. if (model.isEndTimeOK)
  84. {
  85. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(30, 30)];
  86. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  87. maskLayer.frame = self.bounds;
  88. maskLayer.path = maskPath.CGPath;
  89. self.layer.mask = maskLayer;
  90. }else{
  91. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(0, 0)];
  92. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  93. maskLayer.frame = self.bounds;
  94. maskLayer.path = maskPath.CGPath;
  95. self.layer.mask = maskLayer;
  96. self.layer.cornerRadius = 30;
  97. }
  98. break;
  99. }
  100. case DayModelStateEnd:{
  101. self.backgroundColor = StartAndEndColor;
  102. self.lunarCalendarLabel.textColor = [UIColor whiteColor];
  103. // self.gregorianCalendarLabel.text = @"离店";
  104. self.gregorianCalendarLabel.textColor = [UIColor whiteColor];
  105. // self.layer.cornerRadius = 30;
  106. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(30, 30)];
  107. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  108. maskLayer.frame = self.bounds;
  109. maskLayer.path = maskPath.CGPath;
  110. self.layer.mask = maskLayer;
  111. break;
  112. }
  113. case DayModelStateSelected:{
  114. self.backgroundColor = SelectedColor;
  115. self.lunarCalendarLabel.textColor = [UIColor whiteColor];
  116. self.gregorianCalendarLabel.textColor = [UIColor whiteColor];
  117. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(0, 0)];
  118. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  119. maskLayer.frame = self.bounds;
  120. maskLayer.path = maskPath.CGPath;
  121. self.layer.mask = maskLayer;
  122. break;
  123. }
  124. default:
  125. break;
  126. }
  127. }
  128. }
  129. @end