登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

日期选择器、日历

[复制链接]
来自: 秦桥村委会 分类: iOS精品源码 上传时间: 2017-8-30 17:02:48
Tag:

项目介绍:

常见的日历

github地址

常见的日历

之前没做过日历的时候感觉很难,做过一遍之后,发现其实并不是男,只是麻烦了些。因为我为了省事,有些东西只是简单的举一个例子什么的,比较懒。大家有什么需要延伸的功能都可以在里面找下对应的东西。话不多说,看吧。

pragma mark -Private //返回当月天数

(NSUInteger)numberOfDaysInMonth:(NSDate )date{ NSCalendar greCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; return [greCalendar rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:date].length;
}

//返回当月第一天数据

(NSDate )firstDateOfMonth:(NSDate )date{ NSCalendar greCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:date]; comps.day = 1; return [greCalendar dateFromComponents:comps]; }

(NSUInteger)startDayOfWeek:(NSDate )date { NSCalendar greCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];//Asia/Shanghai NSDateComponents *comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:[self firstDateOfMonth:date]]; return comps.weekday; }

//上个月

(NSDate )getLastMonth:(NSDate )date{ NSCalendar greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; comps.month -= 1; return [greCalendar dateFromComponents:comps]; } //下个月
(NSDate )getNextMonth:(NSDate )date{ NSCalendar greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; comps.month += 1; return [greCalendar dateFromComponents:comps]; }
//目标日期

(NSDate )getCurrentMonth:(NSDate )date andYear:(NSInteger)year andMonth:(NSInteger)month andDay:(NSInteger)day{ NSCalendar greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; comps.year = year; comps.month = month; comps.day = day; return [greCalendar dateFromComponents:comps]; }
//当前月

(NSDate )getCurrentMonth:(NSDate )date{ NSCalendar greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; return [greCalendar dateFromComponents:comps]; }
//日期的当天

(NSDate )dateOfDay:(NSInteger)day{ NSCalendar greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; [greCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; NSDateComponents *comps = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:self.chooseDate]; comps.day = day; return [greCalendar dateFromComponents:comps]; }
@end

@implementation CalendarHeaderView

(instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) {

NSArray *weekArray = [[NSArray alloc] initWithObjects:@"日",@"一",@"二",@"三",@"四",@"五",@"六", nil];

for (int i=0; i<weekArray.count; i++) {

  UILabel *weekLabel = [[UILabel alloc] initWithFrame:CGRectMake(i*Iphone6Scale(54), 0, Iphone6Scale(54), HeaderViewHeight)];
  weekLabel.textAlignment = NSTextAlignmentCenter;
  weekLabel.textColor = [UIColor grayColor];
  weekLabel.font = [UIFont systemFontOfSize:13.f];
  weekLabel.text = weekArray[i];
  [self addSubview:weekLabel];

}

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, HeaderViewHeight, self.frame.size.width, 1)];
lineView.backgroundColor = kRGBColor(0, 134, 237);

[self addSubview:lineView];
} return self; } @end

@implementation CalendarCell

(instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { CGFloat width = self.contentView.frame.size.width0.6; CGFloat height = self.contentView.frame.size.height0.6;

// 选中BG
UIView* selectedBGView = [[UIView alloc] initWithFrame:CGRectMake( (self.contentView.width - self.contentView.height) / 2.0, 0, self.contentView.height, self.contentView.height)];
selectedBGView.tag = 9588;
selectedBGView.hidden = YES;
selectedBGView.layer.cornerRadius = selectedBGView.bounds.size.width / 2.0;
selectedBGView.backgroundColor = kRGBColor(24, 147, 239);

UILabel dayLabel = [[UILabel alloc] initWithFrame:CGRectMake( self.contentView.frame.size.width0.5-width0.5, self.contentView.frame.size.height0.5-height*0.5, width, height )];
dayLabel.textAlignment = NSTextAlignmentCenter;

dayLabel.font = [UIFont boldSystemFontOfSize:13];
dayLabel.backgroundColor = [UIColor clearColor];

[self.contentView addSubview:selectedBGView];
[self.contentView addSubview:dayLabel];

self.dayLabel = dayLabel;
} return self; }

(void)setMonthModel:(MonthModel *)monthModel{ _monthModel = monthModel; self.dayLabel.text = [NSString stringWithFormat:@"%02ld",monthModel.dayValue];

if (monthModel.isSelectedDay) { self.dayLabel.text = @"今天"; }

if (monthModel.isCanClick) { self.dayLabel.textColor = [UIColor blackColor]; self.userInteractionEnabled = YES;

} else { self.dayLabel.textColor = [UIColor lightGrayColor]; self.userInteractionEnabled = NO; } }

@end

@implementation MonthModel
|10 [/pan]

相关源码推荐:

我来说两句
*滑动验证:
所有评论(12)
hellokenken 2017-8-31 11:48:01
写的真的很不错
回复
littleRed 2017-8-31 11:48:13
帮帮顶顶!!
回复
AlonMessi 2017-8-31 11:48:15
小弟学习了~支持,支持
回复
phoiu 2017-8-31 11:48:35
内容很好,棒棒哒
回复
BlueManlove 2017-8-31 11:48:41
小弟学习了~支持,支持
回复
kengsir 2017-8-31 11:50:38
感谢分享,code4app有你更精彩
回复
秦桥村委会 2017-8-31 11:56:57
你们这系统评论的太浮夸了点吧。。。
回复
code4app热心网友 2017-8-31 14:47:46
我只是路过打酱油的。
回复
董亚强 2017-8-31 14:48:13
楼主威武啊,Code4App有你更给力!
回复
12下一页
提取码:  下载次数:54 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
502 2 54
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表