DailyCalendarView.m 3.0 KB

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