首先你的下载个第三方框架FSCalendar,链接https://github.com/search?utf8=✓&q=FSCalendar
封装的
#import <UIKit/UIKit.h>
//日期选择的封装 例如2016-10-25
@protocol FSCalendarViewDegelate <NSObject>
-(void)calendarViewTime:(NSString *)time;
@end
@interface FSCalendarView : UIView
@property (nonatomic,strong)id<FSCalendarViewDegelate>delegate;
@property (nonatomic)BOOL isTime;
@property (nonatomic,strong)NSString *selectTime;
@end
#import "FSCalendarView.h"
#import "FSCalendar.h"
@interface FSCalendarView ()<FSCalendarDataSource, FSCalendarDelegate>
@end
@implementation FSCalendarView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self addFSCalendar];
}
return self;
}
-(void)addFSCalendar{
self.backgroundColor = [UIColor groupTableViewBackgroundColor];
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
calendar.dataSource = self;
calendar.delegate = self;
calendar.allowsSelection=YES;
calendar.backgroundColor = [UIColor whiteColor];
[self addSubview:calendar];
}
#pragma mark FSCalendarDelegate
- (NSString *)calendar:(FSCalendar *)calendar titleForDate:(NSDate *)date
{
if([calendar isDateInToday:date]) {
return @"今天";
}
return nil;
}
- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date{
if ([_delegate respondsToSelector:@selector(calendarViewTime:)]){
[_delegate calendarViewTime:[DateTransform dateString_1:date]];
}
if (!_isTime){
[self removeFromSuperview];
}else{
self.selectTime=[DateTransform dateString_1:date];
}
return YES;
}