iOS實現(xiàn)一個簡易日歷代碼
日歷一般都是用UICollectionView進行開發(fā)的,相關(guān)demo也很多,這里就講一個我最近寫的玩的demo,由于時間原因沒來得及加年歷和周歷,一個月歷的小demo,隨著月份天數(shù)的不同,自動改變?nèi)諝v的高。
代理部分:
@protocol KJCalendarDelegate <NSObject> /** 隨著每個月的天數(shù)不一樣而改變高度 @param height 日歷高度 */ - (void)calendarViewHeightChange:(CGFloat)height; /** 當前展示的年和月,當類型是年歷的時候,只返回年 @param year 年 @param month 月 */ - (void)currentShowYear:(NSInteger)year withMonth:(NSInteger)month; /** 選中的時間 @param solar 陽歷 @param lunar 農(nóng)歷 */ - (void)selectSolarDate:(NSString *)solar withLunar:(NSString *)lunar; @end
這個當時創(chuàng)建文件的時候,沒注意,KJCalendar寫成了KJCanlendar,抱歉。。。
下面是可自定義的部分:
//======以下屬性可自定義====== //背景顏色 @property (strong, nonatomic) UIColor *bgColor; //weekView背景色 默認clearcolor @property (strong, nonatomic) UIColor *weekColor; //選擇狀態(tài)下的背景顏色 @property (strong, nonatomic) UIColor *selectBgColor; //選擇狀態(tài)下的字體顏色 @property (strong, nonatomic) UIColor *selectTitleColor; //普通狀態(tài)下公歷字體顏色 @property (strong, nonatomic) UIColor *normalDateTitleColor; //普通狀態(tài)下農(nóng)歷字體顏色 @property (strong, nonatomic) UIColor *normalLunerTitleColor; //今天的字體顏色 @property (strong, nonatomic) UIColor *todayTitleColor; //今天選擇狀態(tài)下的背景顏色 @property (strong, nonatomic) UIColor *todaySelectBgColor; //今天選擇狀態(tài)下的字體顏色 @property (strong, nonatomic) UIColor *todaySelectTitleColor; //距屏幕左右間隔,默認8 @property (assign, nonatomic) CGFloat screenInSpace; //每行(item)的高度,設(shè)置的高度不能大于寬度,寬度的來源是屏幕的寬減去左右間隔除以7得到 @property (assign, nonatomic) CGFloat rowHeight; //設(shè)置是否顯示陰歷 YES-顯示 NO-隱藏 默認YES @property (assign, nonatomic) BOOL isShowLunar; //公歷字體 默認system 13 @property (strong, nonatomic) UIFont *dateFont; //農(nóng)歷字體 默認system 8 @property (strong, nonatomic) UIFont *lunerFont; //選中時公歷字體 默認 [UIFont boldSystemFontOfSize:13.0f]; @property (strong, nonatomic) UIFont *dateSelectFont; //選中時農(nóng)歷字體 默認 [UIFont boldSystemFontOfSize:8.0f]; @property (strong, nonatomic) UIFont *lunerSelectFont;
使用也很簡單:
//高度是根據(jù)日歷的月份天數(shù)決定的 self.calView = [[KJCanlendarView alloc] initWithY:0 withNavc:YES andLeastYear:0]; self.calView.kjDelegate = self; [self.calView showKJCalendarInCtrl:self];
每個屬性都有默認值,需要改變賦值即可,當然啦,設(shè)置字體時,要調(diào)整背景圓圈的大小以及rouHeight的大小,具體的下面我給出demo,就不多說了,大家就隨便看看,寫的很隨意,希望能幫到大家。
demo:KJCalendar_jb51.rar
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS 鍵盤輸入限制(只能輸入字母,數(shù)字,禁止輸入特殊符號)
本文主要介紹了iOS中鍵盤輸入限制(只能輸入字母,數(shù)字,禁止輸入特殊符號)的方法。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04
Flutter Widgets MediaQuery控件屏幕信息適配
這篇文章主要為大家介紹了Flutter Widgets 之 MediaQuery控件獲取屏幕信息和屏幕適配示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11

