第一步 导入文件 文件在我的资源中 http://download.csdn.net/detail/u011463507/9725314
#import "ASWeekSelectorView.h"
@property (strong,nonatomic) ASWeekSelectorView *weekSelector;
第二步创建日历控件
- (ASWeekSelectorView *)weekSelector{
if (_weekSelector ==nil) {
_weekSelector = [[ASWeekSelectorViewalloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,60)];
_weekSelector.delegate =self;
}
return_weekSelector;
}
第三步添加代理 ASWeekSelectorViewDelegate第四步 设置当前选中的日期
self.weekSelector.firstWeekday =2;//设置周一选中
self.weekSelector.letterTextColor = [UIColorcolorWithWhite:.5alpha:1];
self.weekSelector.delegate =self;
NSDate *now = [NSDatedate];
self.weekSelector.selectedDate = now;//设置当前选中的是今天(now)
第五步实现代理方法
- (void)updateLabelForDate:(NSDate *)date
{
NSString *stringDate = [PublicMethodformattedOutput:date];
stringDate = [stringDate substringToIndex:10];
datePickerdate = stringDate;
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc]init];
dateFormatter.timeStyle =NSDateFormatterNoStyle;
dateFormatter.dateStyle =NSDateFormatterFullStyle;
NSLog(@"%@",[dateFormatterstringFromDate:date]);
NSDate *dateNow = [NSDatedate];
NSString *nowDate = [dateFormatterstringFromDate:dateNow];
if ([[dateFormatterstringFromDate:date]isEqualToString:nowDate]) {
if ([self.WatchBlue.strTextisEqualToString:Connected]) {
}else{
[selfshowHUDText:@"请连接手表"];
}
}else{
}
//判断时间如果是在当前时间以前
[selfnetworking:stringDate];
}
- (void)viewWillLayoutSubviews
{
[superviewWillLayoutSubviews];
CGRect frame =self.weekSelector.frame;
frame.size.width =CGRectGetWidth(self.view.frame);
self.weekSelector.frame = frame;
}
、、、、、、、、、、、、
- (void)weekSelector:(ASWeekSelectorView *)weekSelector willSelectDate:(NSDate *)date
{
[selfupdateLabelForDate:date];
}
- (UIColor *)weekSelector:(ASWeekSelectorView *)weekSelector numberColorForDate:(NSDate *)date
{
// NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
// NSInteger weekday = [gregorian component:NSCalendarUnitWeekday fromDate:date];
// if (weekday == 1 || weekday == 7) {
// return [UIColor lightGrayColor];
// } else {
// return nil;
// }
returnnil;
}
- (UIColor *)weekSelector:(ASWeekSelectorView *)weekSelector circleColorForDate:(NSDate *)date
{
NSCalendar *gregorian = [NSCalendarcalendarWithIdentifier:NSCalendarIdentifierGregorian];
NSInteger weekday = [gregoriancomponent:NSCalendarUnitWeekdayfromDate:date];
if (weekday ==2) {
return [UIColorgreenColor];
} else {
returnnil;
}
}
//显示点点暂时不需要
- (BOOL)weekSelector:(ASWeekSelectorView *)weekSelector showIndicatorForDate:(NSDate *)date
{
// NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
// NSInteger weekday = [gregorian component:NSCalendarUnitDay fromDate:date];
// return weekday % 2 == 1;
returnNO;
}