-
Notifications
You must be signed in to change notification settings - Fork 332
add note label for each day #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
|
|
||
| @interface PDTSimpleCalendarViewCell () | ||
|
|
||
| @property (nonatomic, strong) UILabel *noteLabel; | ||
| @property (nonatomic, strong) UILabel *dayLabel; | ||
| @property (nonatomic, strong) NSDate *date; | ||
|
|
||
|
|
@@ -72,6 +73,22 @@ - (id)initWithFrame:(CGRect)frame | |
| if (self) { | ||
| _date = nil; | ||
| _isToday = NO; | ||
|
|
||
| _noteLabel = [[UILabel alloc] init]; | ||
| [self.noteLabel setFont:[UIFont systemFontOfSize:10.0]]; | ||
| [self.noteLabel setTextAlignment:NSTextAlignmentCenter]; | ||
| [self.contentView addSubview:self.noteLabel]; | ||
|
|
||
| //Add the Constraints | ||
| [self.noteLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | ||
| [self.noteLabel setBackgroundColor:[UIColor clearColor]]; | ||
| self.noteLabel.layer.masksToBounds = YES; | ||
|
|
||
| [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.noteLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]]; | ||
| [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.noteLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:2.0 constant:0.0]]; | ||
| [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.noteLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeHeight multiplier:0.3 constant:0.0]]; | ||
| [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.noteLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeWidth multiplier:0.9 constant:0.0]]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we rely on the frame size rather than the PDTSimpleCalendarSize? I think it will be more robust. |
||
|
|
||
| _dayLabel = [[UILabel alloc] init]; | ||
| [self.dayLabel setFont:[self textDefaultFont]]; | ||
| [self.dayLabel setTextAlignment:NSTextAlignmentCenter]; | ||
|
|
@@ -124,6 +141,7 @@ - (void)setCircleColor:(BOOL)today selected:(BOOL)selected | |
| { | ||
| UIColor *circleColor = (today) ? [self circleTodayColor] : [self circleDefaultColor]; | ||
| UIColor *labelColor = (today) ? [self textTodayColor] : [self textDefaultColor]; | ||
| NSString *note = @""; | ||
|
|
||
| if (self.date && self.delegate) { | ||
| if ([self.delegate respondsToSelector:@selector(simpleCalendarViewCell:shouldUseCustomColorsForDate:)] && [self.delegate simpleCalendarViewCell:self shouldUseCustomColorsForDate:self.date]) { | ||
|
|
@@ -135,6 +153,10 @@ - (void)setCircleColor:(BOOL)today selected:(BOOL)selected | |
| if ([self.delegate respondsToSelector:@selector(simpleCalendarViewCell:circleColorForDate:)] && [self.delegate simpleCalendarViewCell:self circleColorForDate:self.date]) { | ||
| circleColor = [self.delegate simpleCalendarViewCell:self circleColorForDate:self.date]; | ||
| } | ||
|
|
||
| if ([self.delegate respondsToSelector:@selector(simpleCalendarViewCell:noteForDate:)] && [self.delegate simpleCalendarViewCell:self noteForDate:self.date]) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the "double" delegate hoop. PDTSimpleCalendar can have a simple |
||
| note = [self.delegate simpleCalendarViewCell:self noteForDate:self.date]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -147,6 +169,16 @@ - (void)setCircleColor:(BOOL)today selected:(BOOL)selected | |
| [self.dayLabel setTextColor:labelColor]; | ||
| } | ||
|
|
||
| - (void)setNote:(NSString *)noteText | ||
| { | ||
| if (noteText == nil || noteText.length == 0) { | ||
| [self.noteLabel setHidden:YES]; | ||
| } else { | ||
| [self.noteLabel setHidden:NO]; | ||
| [self.noteLabel setText:noteText]; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| - (void)refreshCellColors | ||
| { | ||
|
|
@@ -161,6 +193,7 @@ - (void)prepareForReuse | |
| [super prepareForReuse]; | ||
| _date = nil; | ||
| _isToday = NO; | ||
| [self.noteLabel setHidden:YES]; | ||
| [self.dayLabel setText:@""]; | ||
| [self.dayLabel setBackgroundColor:[self circleDefaultColor]]; | ||
| [self.dayLabel setTextColor:[self textDefaultColor]]; | ||
|
|
@@ -277,4 +310,17 @@ - (UIFont *)textDefaultFont | |
| return [UIFont systemFontOfSize:17.0]; | ||
| } | ||
|
|
||
| - (UIFont *)noteFont | ||
| { | ||
| if(_noteFont == nil) { | ||
| _noteFont = [[[self class] appearance] noteFont]; | ||
| } | ||
|
|
||
| if (_noteFont != nil) { | ||
| return _noteFont; | ||
| } | ||
|
|
||
| return [UIFont systemFontOfSize:10.0]; | ||
| } | ||
|
|
||
| @end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow customization of this font using UIAppearance? That could be handy.