您的当前位置:首页正文

FSCalendar使用介绍(一) - Hello World

来源:华拓网

FSCalendar是一款开源iOS日历控件,支持横向、纵向滑动模式,全屏模式,带有子标题、事件设置等功能。以下是项目截图:


iPhone.jpg
iPad.jpg
  • 另外也可以用来做通知中心的插件:


    FSCalenar.gif

    当然如果想要在安装之前看一下效果,CocoaPods还提供了一种预览实例的模式,直接执行:

    pod try FSCalendar
    

    2. 手动安装

    手动安装的方式比较简单,在中点击Download Zip,然后将FSCalendar文件夹拖进你的项目中,确保Copy items if needed被选中即可


    点击download.png 选中Copy items if needed.png

    这样就可以在项目中使用FSCalendar了:)。

    • 还有一种安装方式是通过,但是貌似用的人比较少,就不再赘述了。如果你的项目中用到了,就在Cartfile中添加:
    github "WenchaoD/FSCalendar"
    

    二、使用方法

    方式1. 不使用Interface Builder

    // ViewController.h
    
    #import <UIKit/UIKit.h>
    #import "FSCalendar.h"
    
    @interface ViewController : UIViewController <FSCalendarDataSource, FSCalendarDelegate>
    
    @property (weak, nonatomic) FSCalendar *calendar;
    
    @end
    
    // ViewController.m
    
    #import "ViewController.h"
    
    @implementation ViewController
    
    - (void)loadView
    {
        UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        view.backgroundColor = [UIColor groupTableViewBackgroundColor];
        self.view = view;
        
        FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, view.frame.size.width, 300)];
        calendar.dataSource = self;
        calendar.delegate = self;
        calendar.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:calendar];
        self.calendar = calendar;
    }
    
    @end
    

    效果图:


    loadView.png

    综上:

    • 如果当前的VC不使用Interface Builder,请覆盖这个方法,反之如果使用了,则一定不能覆盖这个方法(you must not override this method)。
    • loadView这个方法负责创建当前VC的根视图的视图层级(view hierachy),在这里给self.view赋值(non-nil value),并且不要调用[super loadView];(Your custom implementation of this method should not call super);
    • viewDidLoad用来做额外的初始化(additional initialization);

    方式2. 使用Interface Builder

    直接拖动一个UIView的Object,将Custom Class 设置成为FSCalendar即可,这里需要将FSCalendar的dataSource和delegate属性连接到你的VC上,如下图所示: