FSCalendar的简单封装和使用

首先你的下载个第三方框架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;

}

使用方法调用那个代理就可以了


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值