DailyCalendarView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // DailyCalendarView.m
  3. // Deputy
  4. //
  5. // Created by Caesar on 30/10/2014.
  6. // Copyright (c) 2014 Caesar Li
  7. //
  8. #import "DailyCalendarView.h"
  9. #import "NSDate+CL.h"
  10. #import "UIColor+CL.h"
  11. #import "BRDatePickerView.h"
  12. @interface DailyCalendarView()
  13. @property (nonatomic, strong) UILabel *dateLabel;
  14. @property (nonatomic, strong) UIView *dateLabelContainer;
  15. @end
  16. #define DATE_LABEL_SIZE 28
  17. #define DATE_LABEL_FONT_SIZE 13
  18. @implementation DailyCalendarView
  19. - (id)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. // Initialization code
  24. [self addSubview:self.dateLabelContainer];
  25. UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dailyViewDidClick:)];
  26. [self addGestureRecognizer:singleFingerTap];
  27. }
  28. return self;
  29. }
  30. -(UIView *)dateLabelContainer
  31. {
  32. if(!_dateLabelContainer){
  33. float x = (self.bounds.size.width - DATE_LABEL_SIZE)/2;
  34. _dateLabelContainer = [[UIView alloc] initWithFrame:CGRectMake(x, 0, DATE_LABEL_SIZE, DATE_LABEL_SIZE)];
  35. _dateLabelContainer.backgroundColor = [UIColor clearColor];
  36. _dateLabelContainer.layer.cornerRadius = DATE_LABEL_SIZE/2;
  37. _dateLabelContainer.clipsToBounds = YES;
  38. [_dateLabelContainer addSubview:self.dateLabel];
  39. }
  40. return _dateLabelContainer;
  41. }
  42. -(UILabel *)dateLabel
  43. {
  44. if(!_dateLabel){
  45. _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, DATE_LABEL_SIZE, DATE_LABEL_SIZE)];
  46. _dateLabel.backgroundColor = [UIColor clearColor];
  47. _dateLabel.textColor = [UIColor whiteColor];
  48. _dateLabel.textAlignment = NSTextAlignmentCenter;
  49. _dateLabel.font = [UIFont systemFontOfSize:DATE_LABEL_FONT_SIZE];
  50. }
  51. return _dateLabel;
  52. }
  53. -(void)setDate:(NSDate *)date
  54. {
  55. _date = date;
  56. [self setNeedsDisplay];
  57. }
  58. -(void)setBlnSelected: (BOOL)blnSelected
  59. {
  60. _blnSelected = blnSelected;
  61. [self setNeedsDisplay];
  62. }
  63. // Only override drawRect: if you perform custom drawing.
  64. // An empty implementation adversely affects performance during animation.
  65. - (void)drawRect:(CGRect)rect
  66. {
  67. self.dateLabel.text = [self.date getDateOfMonth];
  68. }
  69. -(void)markSelected:(BOOL)blnSelected
  70. {
  71. self.dateLabelContainer.backgroundColor = (blnSelected)?[UIColor redColor]: [UIColor clearColor];
  72. self.dateLabel.textColor = (blnSelected)?[UIColor whiteColor]:[self colorByDate];
  73. }
  74. -(UIColor *)colorByDate
  75. {
  76. return [self.date isPastDate]?[UIColor colorWithHex:0x000000]:[UIColor blackColor];
  77. }
  78. -(void)dailyViewDidClick: (UIGestureRecognizer *)tap
  79. {
  80. [self.delegate dailyCalendarViewDidSelect: self.date];
  81. }
  82. @end