You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
3.7 KiB
149 lines
3.7 KiB
// |
|
// EBCalendarDayCell.m |
|
// EBCalendarViewDemo |
|
// |
|
// Created by HoYo on 2018/4/26. |
|
// Copyright © 2018年 HoYo. All rights reserved. |
|
// |
|
|
|
#import "EBCalendarDayCell.h" |
|
#import "UIColor+EBAdd.h" |
|
#import "EBCalendarModel.h" |
|
|
|
@interface EBCalendarDayCell() |
|
@property (nonatomic, strong) UILabel *dayLabel; |
|
|
|
@property (nonatomic ,strong) UIImageView *signImage; |
|
|
|
|
|
@property (nonatomic ,strong) UIView *bgView; |
|
@end |
|
CGFloat const EBCalendarDayCellDayWidth = 28; |
|
@implementation EBCalendarDayCell |
|
- (id)initWithFrame:(CGRect)frame { |
|
self = [super initWithFrame:frame]; |
|
if (self) { |
|
[self setupView]; |
|
[self setupFrame]; |
|
} |
|
return self; |
|
} |
|
|
|
#pragma mark - Setup |
|
|
|
- (void)setupView { |
|
[self.contentView addSubview:self.bgView]; |
|
[self.contentView addSubview:self.signImage]; |
|
[self.contentView addSubview:self.dayLabel]; |
|
} |
|
|
|
- (void)setupFrame { |
|
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.centerX.equalTo(self.contentView); |
|
make.size.mas_equalTo(CGSizeMake(EBCalendarDayCellDayWidth, EBCalendarDayCellDayWidth)); |
|
}]; |
|
|
|
[self.signImage mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.centerX.equalTo(self.contentView); |
|
make.size.mas_equalTo(self.signImage.image.size); |
|
}]; |
|
_dayLabel.frame = CGRectMake(CGRectGetWidth(self.contentView.bounds) / 2 - EBCalendarDayCellDayWidth / 2 |
|
, CGRectGetHeight(self.contentView.bounds) / 2 - EBCalendarDayCellDayWidth / 2 |
|
, EBCalendarDayCellDayWidth |
|
, EBCalendarDayCellDayWidth); |
|
|
|
} |
|
|
|
#pragma mark - Public |
|
- (void)configWithCalendarModel:(EBCalendarModel*)model |
|
{ |
|
// 上月的数据显示为空,并且不能点击 |
|
if(model.year == 0) |
|
{ |
|
_dayLabel.text = @""; |
|
} |
|
else |
|
{ |
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
|
[formatter setDateFormat:@"dd"]; |
|
NSString *dayString = [formatter stringFromDate:[NSDate date]]; |
|
[formatter setDateFormat:@"MM"]; |
|
NSString *monthString = [formatter stringFromDate:[NSDate date]]; |
|
|
|
if(model.day == dayString.intValue && model.month == monthString.intValue) |
|
{ |
|
_dayLabel.text = @"今"; |
|
} |
|
else |
|
{ |
|
_dayLabel.text = @(model.day).stringValue; |
|
} |
|
|
|
} |
|
|
|
[self styleOfNormalDay]; |
|
|
|
// if (model.isSelected) { |
|
// [self styleOfSelectedDay]; |
|
// } |
|
self.signImage.hidden = !model.isSelected; |
|
if (model.isToday) { |
|
[self styleOfToday]; |
|
} |
|
} |
|
|
|
#pragma mark Private |
|
- (void)styleOfSelectedDay |
|
{ |
|
_bgView.backgroundColor = KKClearColor; |
|
} |
|
|
|
- (void)styleOfToday |
|
{ |
|
_bgView.backgroundColor = mainColor; |
|
} |
|
|
|
- (void)styleOfNormalDay |
|
{ |
|
_bgView.backgroundColor = KKClearColor; |
|
} |
|
|
|
#pragma mark Getter |
|
- (UILabel*)dayLabel |
|
{ |
|
if (!_dayLabel) { |
|
_dayLabel = [UILabel new]; |
|
_dayLabel.font = Font_(14); |
|
_dayLabel.textColor = KKTextColor; |
|
_dayLabel.backgroundColor = KKClearColor; |
|
// _dayLabel.layer.cornerRadius = EBCalendarDayCellDayWidth * 0.5; |
|
// _dayLabel.layer.masksToBounds = YES; |
|
_dayLabel.textAlignment = NSTextAlignmentCenter; |
|
} |
|
return _dayLabel; |
|
} |
|
|
|
- (UIImageView *)signImage |
|
{ |
|
if (!_signImage) |
|
{ |
|
_signImage = [UIImageView new]; |
|
_signImage.hidden = YES; |
|
_signImage.image = ImageName_(@"sign_checked_img"); |
|
} |
|
return _signImage; |
|
} |
|
|
|
- (UIView *)bgView |
|
{ |
|
if (!_bgView) |
|
{ |
|
_bgView = [UIView new]; |
|
_bgView.layer.cornerRadius = EBCalendarDayCellDayWidth * 0.5; |
|
_bgView.layer.masksToBounds = YES; |
|
|
|
} |
|
return _bgView; |
|
} |
|
@end
|
|
|