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.

122 lines
4.0 KiB

2 years ago
//
// EBCalenderNavigationView.m
// EBCalendarViewDemo
//
// Created by HoYo on 2018/5/3.
// Copyright © 2018HoYo. All rights reserved.
//
#import "EBCalenderNavigationView.h"
#import "UIColor+EBAdd.h"
#import "NSDate+EBAdd.h"
@interface EBCalenderNavigationView()
@property (nonatomic, strong) UIButton *lastMonthButton, *nextMonthButton;
@property (nonatomic, strong) UILabel *showDateLabel;
@end
static CGFloat const kEBCalenderNavigationViewButtonWidth = 70;
@implementation EBCalenderNavigationView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = KKWhiteColorColor;
[self setupView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
[self setupFrame];
}
#pragma mark - Setup
- (void)setupView {
[self addSubview:self.showDateLabel];
[self addSubview:self.lastMonthButton];
[self addSubview:self.nextMonthButton];
}
- (void)setupFrame
{
// CGFloat viewHeight = CGRectGetHeight(self.bounds)
// , viewWidth = CGRectGetWidth(self.bounds);
// _lastMonthButton.frame = CGRectMake(0, 0, kEBCalenderNavigationViewButtonWidth, viewHeight);
// _showDateLabel.frame = CGRectMake(CGRectGetMaxX(_lastMonthButton.frame) + 1, 0, viewWidth - kEBCalenderNavigationViewButtonWidth * 2 - 2, 90);
// _nextMonthButton.frame = CGRectMake(CGRectGetMaxX(_showDateLabel.frame) + 1, 0, kEBCalenderNavigationViewButtonWidth, viewHeight);
[_showDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.centerY.equalTo(self);
make.width.mas_equalTo(95);
}];
[_nextMonthButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.left.equalTo(_showDateLabel.mas_right).offset(16);
make.size.mas_equalTo(CGSizeMake(28, 28));
}];
[_lastMonthButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.right.equalTo(_showDateLabel.mas_left).inset(16);
make.size.mas_equalTo(CGSizeMake(28, 28));
}];
}
#pragma mark - Events
- (void)changeMonthAction:(UIButton*)button
{
BOOL isNextMonth = NO;
if ([button isEqual:_nextMonthButton])
{
// 下个月
isNextMonth = YES;
}
if ([self.delegate respondsToSelector:@selector(calenderNavigationViewDidChangeMonth:isNextMonth:)])
{
[self.delegate calenderNavigationViewDidChangeMonth:self isNextMonth:isNextMonth];
}
}
#pragma mark - Setter
- (void)setShowDate:(NSString *)showDate {
_showDate = showDate;
_showDateLabel.text = showDate;
}
#pragma mark - Getter
- (UILabel*)showDateLabel {
if (!_showDateLabel) {
_showDateLabel = [UILabel new];
//_showDateLabel.backgroundColor = [UIColor colorWithHexString:@"00b5b3"];
_showDateLabel.textColor = mainColor;
_showDateLabel.font = FontBold_(16);
_showDateLabel.textAlignment = NSTextAlignmentCenter;
// 默认显示当前年月
_showDateLabel.text = [[NSDate date] stringWithFormat:@"yyyy年MM月"];
}
return _showDateLabel;
}
- (UIButton*)lastMonthButton {
if (!_lastMonthButton) {
_lastMonthButton = [UIButton new];
//_lastMonthButton.backgroundColor = [UIColor colorWithHexString:@"00b5b3"];
[_lastMonthButton setImage:[UIImage imageNamed:@"left_last_mounth_img"] forState:UIControlStateNormal];
[_lastMonthButton addTarget:self action:@selector(changeMonthAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _lastMonthButton;
}
- (UIButton*)nextMonthButton {
if (!_nextMonthButton) {
_nextMonthButton = [UIButton new];
//_nextMonthButton.backgroundColor = [UIColor colorWithHexString:@"00b5b3"];
[_nextMonthButton setImage:[UIImage imageNamed:@"right_next_mounth_img"] forState:UIControlStateNormal];
[_nextMonthButton addTarget:self action:@selector(changeMonthAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _nextMonthButton;
}
@end