Add event label below
This commit is contained in:
parent
d52588f759
commit
07f99ea8cc
|
|
@ -23,6 +23,8 @@ typedef NS_ENUM(NSUInteger, SelectionType) {
|
|||
|
||||
@property (weak, nonatomic) FSCalendar *calendar;
|
||||
|
||||
@property (weak, nonatomic) UILabel *eventLabel;
|
||||
|
||||
@property (strong, nonatomic) NSCalendar *gregorian;
|
||||
@property (strong, nonatomic) NSDateFormatter *dateFormatter;
|
||||
|
||||
|
|
@ -57,13 +59,27 @@ typedef NS_ENUM(NSUInteger, SelectionType) {
|
|||
|
||||
calendar.calendarHeaderView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];
|
||||
calendar.calendarWeekdayView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];
|
||||
|
||||
calendar.appearance.eventSelectionColor = [UIColor whiteColor];
|
||||
calendar.appearance.eventOffset = CGPointMake(0, -7);
|
||||
|
||||
calendar.today = nil;
|
||||
|
||||
calendar.today = nil; // Hide the today circle
|
||||
[calendar registerClass:[DIVCalendarCell class] forCellReuseIdentifier:@"cell"];
|
||||
|
||||
|
||||
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(calendar.frame)+10, self.view.frame.size.width, 50)];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
|
||||
[self.view addSubview:label];
|
||||
self.eventLabel = label;
|
||||
|
||||
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:@""];
|
||||
NSTextAttachment *attatchment = [[NSTextAttachment alloc] init];
|
||||
attatchment.image = [UIImage imageNamed:@"icon_cat"];
|
||||
attatchment.bounds = CGRectMake(0, -3, attatchment.image.size.width, attatchment.image.size.height);
|
||||
[attributedText appendAttributedString:[NSAttributedString attributedStringWithAttachment:attatchment]];
|
||||
[attributedText appendAttributedString:[[NSAttributedString alloc] initWithString:@" Hey Daily Event "]];
|
||||
[attributedText appendAttributedString:[NSAttributedString attributedStringWithAttachment:attatchment]];
|
||||
self.eventLabel.attributedText = attributedText.copy;
|
||||
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
|
|
@ -96,7 +112,6 @@ typedef NS_ENUM(NSUInteger, SelectionType) {
|
|||
- (FSCalendarCell *)calendar:(FSCalendar *)calendar cellForDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)position
|
||||
{
|
||||
DIVCalendarCell *cell = [calendar dequeueReusableCellWithIdentifier:@"cell" forDate:date atMonthPosition:position];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
|
@ -104,72 +119,69 @@ typedef NS_ENUM(NSUInteger, SelectionType) {
|
|||
{
|
||||
|
||||
DIVCalendarCell *divCell = (DIVCalendarCell *)cell;
|
||||
switch (position) {
|
||||
case FSCalendarMonthPositionCurrent: {
|
||||
|
||||
divCell.eventIndicator.hidden = NO;
|
||||
|
||||
BOOL isToday = [self.gregorian isDateInToday:date];
|
||||
|
||||
divCell.circleImageView.hidden = !isToday;
|
||||
|
||||
SelectionType selectionType = SelectionTypeNone;
|
||||
|
||||
// Custom today circle
|
||||
divCell.circleImageView.hidden = ![self.gregorian isDateInToday:date];
|
||||
|
||||
|
||||
// Configure selection layer
|
||||
if (position == FSCalendarMonthPositionCurrent || self.calendar.scope == FSCalendarScopeWeek) {
|
||||
|
||||
divCell.eventIndicator.hidden = NO;
|
||||
|
||||
SelectionType selectionType = SelectionTypeNone;
|
||||
if ([calendar.selectedDates containsObject:date]) {
|
||||
NSDate *previousDate = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:-1 toDate:date options:0];
|
||||
NSDate *nextDate = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
|
||||
if ([calendar.selectedDates containsObject:date]) {
|
||||
NSDate *previousDate = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:-1 toDate:date options:0];
|
||||
NSDate *nextDate = [self.gregorian dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
|
||||
if ([calendar.selectedDates containsObject:date]) {
|
||||
if ([calendar.selectedDates containsObject:previousDate] && [calendar.selectedDates containsObject:nextDate]) {
|
||||
selectionType = SelectionTypeMiddle;
|
||||
} else if ([calendar.selectedDates containsObject:previousDate] && [calendar.selectedDates containsObject:date]) {
|
||||
selectionType = SelectionTypeRightBorder;
|
||||
} else if ([calendar.selectedDates containsObject:nextDate]) {
|
||||
selectionType = SelectionTypeLeftBorder;
|
||||
} else {
|
||||
selectionType = SelectionTypeSingle;
|
||||
}
|
||||
if ([calendar.selectedDates containsObject:previousDate] && [calendar.selectedDates containsObject:nextDate]) {
|
||||
selectionType = SelectionTypeMiddle;
|
||||
} else if ([calendar.selectedDates containsObject:previousDate] && [calendar.selectedDates containsObject:date]) {
|
||||
selectionType = SelectionTypeRightBorder;
|
||||
} else if ([calendar.selectedDates containsObject:nextDate]) {
|
||||
selectionType = SelectionTypeLeftBorder;
|
||||
} else {
|
||||
selectionType = SelectionTypeSingle;
|
||||
}
|
||||
} else {
|
||||
selectionType = SelectionTypeNone;
|
||||
}
|
||||
|
||||
|
||||
if (selectionType == SelectionTypeNone) {
|
||||
divCell.selectionLayer.hidden = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
divCell.selectionLayer.hidden = NO;
|
||||
|
||||
if (selectionType == SelectionTypeMiddle) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRect:divCell.selectionLayer.bounds].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeLeftBorder) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:divCell.selectionLayer.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft cornerRadii:CGSizeMake(divCell.selectionLayer.fs_width/2, divCell.selectionLayer.fs_width/2)].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeRightBorder) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:divCell.selectionLayer.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight cornerRadii:CGSizeMake(divCell.selectionLayer.fs_width/2, divCell.selectionLayer.fs_width/2)].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeSingle) {
|
||||
|
||||
CGFloat diameter = MIN(divCell.selectionLayer.fs_height, divCell.selectionLayer.fs_width);
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(divCell.contentView.fs_width/2-diameter/2, divCell.contentView.fs_height/2-diameter/2, diameter, diameter)].CGPath;
|
||||
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
} else {
|
||||
selectionType = SelectionTypeNone;
|
||||
}
|
||||
case FSCalendarMonthPositionPrevious:
|
||||
case FSCalendarMonthPositionNext: {
|
||||
divCell.circleImageView.hidden = YES;
|
||||
|
||||
if (selectionType == SelectionTypeNone) {
|
||||
divCell.selectionLayer.hidden = YES;
|
||||
divCell.eventIndicator.hidden = YES; // Hide default event indicator
|
||||
return;
|
||||
}
|
||||
|
||||
divCell.selectionLayer.hidden = NO;
|
||||
|
||||
if (selectionType == SelectionTypeMiddle) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRect:divCell.selectionLayer.bounds].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeLeftBorder) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:divCell.selectionLayer.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft cornerRadii:CGSizeMake(divCell.selectionLayer.fs_width/2, divCell.selectionLayer.fs_width/2)].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeRightBorder) {
|
||||
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:divCell.selectionLayer.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight cornerRadii:CGSizeMake(divCell.selectionLayer.fs_width/2, divCell.selectionLayer.fs_width/2)].CGPath;
|
||||
|
||||
} else if (selectionType == SelectionTypeSingle) {
|
||||
|
||||
CGFloat diameter = MIN(divCell.selectionLayer.fs_height, divCell.selectionLayer.fs_width);
|
||||
divCell.selectionLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(divCell.contentView.fs_width/2-diameter/2, divCell.contentView.fs_height/2-diameter/2, diameter, diameter)].CGPath;
|
||||
|
||||
}
|
||||
|
||||
} else if (position == FSCalendarMonthPositionNext || position == FSCalendarMonthPositionPrevious) {
|
||||
|
||||
divCell.circleImageView.hidden = YES;
|
||||
divCell.selectionLayer.hidden = YES;
|
||||
divCell.eventIndicator.hidden = YES; // Hide default event indicator
|
||||
if ([self.calendar.selectedDates containsObject:date]) {
|
||||
divCell.titleLabel.textColor = self.calendar.appearance.titlePlaceholderColor; // Prevent placeholders from changing text color
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -182,14 +194,15 @@ typedef NS_ENUM(NSUInteger, SelectionType) {
|
|||
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
|
||||
{
|
||||
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
|
||||
|
||||
self.eventLabel.frame = CGRectMake(0, CGRectGetMaxY(calendar.frame)+10, self.view.frame.size.width, 50);
|
||||
|
||||
}
|
||||
|
||||
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
|
||||
{
|
||||
NSLog(@"did select date %@",[self.dateFormatter stringFromDate:date]);
|
||||
|
||||
[calendar reloadData];
|
||||
|
||||
}
|
||||
|
||||
- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@
|
|||
{
|
||||
switch (self.calendar.scope) {
|
||||
case FSCalendarScopeWeek:
|
||||
return [self weekForSection:section];
|
||||
return [self.gregorian fs_middleDayOfWeek:[self weekForSection:section]];
|
||||
case FSCalendarScopeMonth:
|
||||
return [self monthForSection:section];
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@
|
|||

|
||||
|
||||
## Fully DIV support
|
||||

|
||||
|  |
|
||||
| ------------- |
|
||||
|
||||
|
||||
## Working with AutoLayout and Orientation
|
||||
|
|
|
|||
Loading…
Reference in New Issue