iOS 日歷功能

公司項目有簽到日歷的功能,可自定義設(shè)置最小日期及最大日期慎玖。設(shè)置選中日期的背景顏色和背景圖片幸撕〉乓希可根據(jù)后臺返回的數(shù)據(jù)實現(xiàn)幾個選中的日期功能。

- (void)viewDidLoad {

[super viewDidLoad];

[self loadSignatureData];

self.navigationItem.title = @"每日簽到";

self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];

}

- (void)setupCalendarViewCell

{

FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(15, 360, KscreenWidth-30, 300)];

calendar.dataSource = self;

calendar.delegate = self;

calendar.appearance.weekdayTextColor=mainColor;

calendar.appearance.headerTitleColor=mainColor;

calendar.allowsMultipleSelection = YES;

[self.tableView addSubview:calendar];

self.calendar = calendar;

calendar.calendarHeaderView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9];

calendar.calendarWeekdayView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9];

calendar.appearance.selectionColor =[UIColor clearColor];//選中顏色

calendar.today = nil; // Hide the today circle

[calendar registerClass:[DIYCalendarCell class] forCellReuseIdentifier:@"cell"];

}

//定制今天的日期還有好多有趣的API可以自己去看看

- (NSString *)calendar:(FSCalendar *)calendar titleForDate:(NSDate *)date

{

if ([self.gregorian isDateInToday:date]) {

return @"今";

}

return nil;

}

- (void)dealloc

{

//? ? NSLog(@"%s",__FUNCTION__);

}

#pragma mark - FSCalendarDataSource

//設(shè)置最小日期

- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar

{

return [self.dateFormatter dateFromString:@"2017-08-01"];

}

//最大

- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar

{

return [self.gregorian dateByAddingUnit:NSCalendarUnitMonth value:0 toDate:[NSDate date] options:0];

}

//定制cell

- (FSCalendarCell *)calendar:(FSCalendar *)calendar cellForDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition

{

DIYCalendarCell *cell = [calendar dequeueReusableCellWithIdentifier:@"cell" forDate:date atMonthPosition:monthPosition];

//定制圖片

//cell.circleImageView.image=[UIImage imageNamed:@"勾16"];

return cell;

}

#pragma mark - FSCalendarDelegate

- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition

{

//當(dāng)天不能點擊

if ([self.gregorian isDateInToday:date]) {

return NO;

}else{

return YES;

}

}

- (BOOL)calendar:(FSCalendar *)calendar shouldDeselectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition

{

return YES;

}

- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition

{

NSLog(@"did select date %@",[self.dateFormatter stringFromDate:date]);

if ([_dataArr containsObject:[self.dateFormatter stringFromDate:date]]) {

return;

}

if (![_dataArr containsObject:[self.dateFormatter stringFromDate:date]]) {

[calendar reloadData];

}else{

//重復(fù)的不加

}

}

- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition

{

NSLog(@"did deselect date %@",[self.dateFormatter stringFromDate:date]);

}

- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleSelectionColorForDate:(NSDate *)date{

return [UIColor blackColor];

}

////點擊今日簽到的方法

//-(void)clickQiandao

//{

//? ? if (![_dataArr containsObject:[self.dateFormatter stringFromDate:[NSDate date]]]) {

//? ? ? ? [_dataArr addObject:[self.dateFormatter stringFromDate:[NSDate date]]];

//

//? ? ? ? for (int i=0; i<_dataArr.count; i++) {

//? ? ? ? ? ? [self.calendar selectDate:[self.dateFormatter dateFromString:_dataArr[i]] scrollToDate:YES];

//? ? ? ? }

//

//? ? ? ? [_calendar reloadData];

//? ? }

//}

- (CGFloat)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderRadiusForDate:(nonnull NSDate *)date

{

return 0.0;

}

- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date

{

//點擊簽到按鈕

if ([self.gregorian isDateInToday:date]) {

UIImage * img = [UIImage imageNamed:@"勾16"];

return img;

}

else if ([_dataArr containsObject:[self.dateFormatter stringFromDate:date]]) {

return [UIImage imageNamed:@"勾16"];

//? ? ? ? ? @"對勾"

}

else{

return nil;

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末郑兴,一起剝皮案震驚了整個濱河市犀斋,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌情连,老刑警劉巖叽粹,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機随抠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來持钉,“玉大人衡招,你說我怎么就攤上這事篱昔。” “怎么了始腾?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵州刽,是天一觀的道長。 經(jīng)常有香客問我浪箭,道長穗椅,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任奶栖,我火速辦了婚禮匹表,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘宣鄙。我一直安慰自己袍镀,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布冻晤。 她就那樣靜靜地躺著苇羡,像睡著了一般。 火紅的嫁衣襯著肌膚如雪鼻弧。 梳的紋絲不亂的頭發(fā)上设江,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天,我揣著相機與錄音攘轩,去河邊找鬼叉存。 笑死,一個胖子當(dāng)著我的面吹牛度帮,可吹牛的內(nèi)容都是我干的歼捏。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼甫菠!你這毒婦竟也來了挠铲?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤寂诱,失蹤者是張志新(化名)和其女友劉穎拂苹,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體痰洒,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡瓢棒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了丘喻。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片脯宿。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖泉粉,靈堂內(nèi)的尸體忽然破棺而出连霉,到底是詐尸還是另有隱情,我是刑警寧澤嗡靡,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布跺撼,位于F島的核電站,受9級特大地震影響讨彼,放射性物質(zhì)發(fā)生泄漏歉井。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一哈误、第九天 我趴在偏房一處隱蔽的房頂上張望哩至。 院中可真熱鬧,春花似錦蜜自、人聲如沸菩貌。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽菜谣。三九已至,卻和暖如春晚缩,著一層夾襖步出監(jiān)牢的瞬間尾膊,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工荞彼, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留冈敛,地道東北人。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓鸣皂,卻偏偏與公主長得像抓谴,于是被迫代替她去往敵國和親暮蹂。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容