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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS 鍵盤輸入限制(只能輸入字母,數(shù)字,禁止輸入特殊符號(hào))
本文主要介紹了iOS中鍵盤輸入限制(只能輸入字母,數(shù)字,禁止輸入特殊符號(hào))的方法。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04
iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化實(shí)例代碼
這篇文章主要介紹了iOS中時(shí)間與時(shí)間戳的相互轉(zhuǎn)化實(shí)例代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。2017-03-03
Flutter Widgets MediaQuery控件屏幕信息適配
這篇文章主要為大家介紹了Flutter Widgets 之 MediaQuery控件獲取屏幕信息和屏幕適配示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
iOS tableView實(shí)現(xiàn)搜索功能
這篇文章主要為大家詳細(xì)介紹了iOS tableView實(shí)現(xiàn)搜索功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
iOS開源一個(gè)簡(jiǎn)單的訂餐app UI框架
這篇文章主要介紹了iOS開源一個(gè)簡(jiǎn)單的訂餐app UI框架,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10

