【代码笔记】iOS-日历
一, 效果图。
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h>
#import "CalendarView.h"
#import "CalendarUtils.h"
#import "CalendarStyle.h"
@interface RootViewController : UIViewController
<CalendarViewDelegate>
{
CalendarView *calendarView;
}
@end
RootViewController.m
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title=@"Calendar";
[self initWithCalendarView];
}
-(void)initWithCalendarView
{
if(calendarView)
[calendarView removeFromSuperview];
calendarView = [[CalendarView alloc]initWithFrame:CGRectMake(10, self.view.bounds.size.height - 200 - 320 + 20, 300, 300)];
[calendarView refleshriCheng:^(NSDate *date,NSString *str) {
if([str isEqualToString:@"left"]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了左侧按钮" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
else if([str isEqualToString:@"right"]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了右侧按钮" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
}];
calendarView.delegate=self;
[self.view addSubview:calendarView];
}
#pragma -mark -CalendarViewDelegate
- (void) calendarViewDidSelectDate:(NSDate *)date todayDate:(NSDate *)todayDate
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了日期" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
一, 效果图。
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h>
#import "CalendarView.h"
#import "CalendarUtils.h"
#import "CalendarStyle.h"
@interface RootViewController : UIViewController
<CalendarViewDelegate>
{
CalendarView *calendarView;
}
@end
RootViewController.m
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title=@"Calendar";
[self initWithCalendarView];
}
-(void)initWithCalendarView
{
if(calendarView)
[calendarView removeFromSuperview];
calendarView = [[CalendarView alloc]initWithFrame:CGRectMake(10, self.view.bounds.size.height - 200 - 320 + 20, 300, 300)];
[calendarView refleshriCheng:^(NSDate *date,NSString *str) {
if([str isEqualToString:@"left"]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了左侧按钮" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
else if([str isEqualToString:@"right"]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了右侧按钮" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
}];
calendarView.delegate=self;
[self.view addSubview:calendarView];
}
#pragma -mark -CalendarViewDelegate
- (void) calendarViewDidSelectDate:(NSDate *)date todayDate:(NSDate *)todayDate
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"点击了日期" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}