日歷一般都是用UICollectionView進(jìn)行開(kāi)發(fā)的,相關(guān)demo也很多,這里就講一個(gè)我最近寫(xiě)的玩的demo,由于時(shí)間原因沒(méi)來(lái)得及加年歷和周歷,一個(gè)月歷的小demo,隨著月份天數(shù)的不同,自動(dòng)改變?nèi)諝v的高。
代理部分:
@protocol KJCalendarDelegate <NSObject>/** 隨著每個(gè)月的天數(shù)不一樣而改變高度 @param height 日歷高度 */- (void)calendarViewHeightChange:(CGFloat)height;/** 當(dāng)前展示的年和月,當(dāng)類(lèi)型是年歷的時(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í)候,沒(méi)注意,KJCalendar寫(xiě)成了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è)置的高度不能大于寬度,寬度的來(lái)源是屏幕的寬減去左右間隔除以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,就不多說(shuō)了,大家就隨便看看,寫(xiě)的很隨意,希望能幫到大家。
demo:KJCalendar_jb51.rar
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選