iOS控制項之日曆

2021-07-10 03:47:05 字數 3995 閱讀 2073

這裡是我封裝的collectionview,繼承uicollectionview

首先是.h檔案

#import 

@inte***ce

thccalendar : uicollectionview

@property (nonatomic,assign)nsinteger year;

@property (nonatomic,assign)nsinteger month;

@property (nonatomic,assign)nsinteger day;

- (instancetype)initwithframe:(cgrect)frame collectionviewlayout:(nonnull uicollectionviewlayout *)layout andcellname:(nsstring *)name andcellid:(nsstring *)cellid;

-(void)lastmonthclick;

-(void)nextbuttonclick;

@end

然後是.m檔案

#import "thccalendar.h"

#import "collectionviewcell1.h"

#define width [uiscreen mainscreen].bounds.size.width

#define height [uiscreen mainscreen].bounds.size.height

@inte***ce

thccalendar ()

/* ****用來存放天數的陣列

*/@property (nonatomic,strong)nsarray * weekarray;

@property (nonatomic,strong)nsmutablearray * dayarray;

@property (nonatomic,strong)nsdatecomponents * nowdate;

@property (nonatomic,strong)nscalendar *calendar;

@property (nonatomic,strong)nsdate *lastmonthdate;

@property (nonatomic,strong)nsdate *nowmonthfirst;

@property (nonatomic,copy)nsstring * cellid;

@end

@implementation

thccalendar

//name是cell的name cellid是cell的id

- (instancetype)initwithframe:(cgrect)frame collectionviewlayout:(nonnull uicollectionviewlayout *)layout andcellname:(nsstring *)name andcellid:(nsstring *)cellid

return

self;

}//請求下乙個月的資料

-(void)nextbuttonclickelse

[self setmydayarraywithyear:_year andmonth:_month andday:_day];

[self reloaddata];

}//請求上乙個月的資料

-(void)lastmonthclickelse

[self setmydayarraywithyear:_year andmonth:_month andday:_day];

[self reloaddata];

}//初始化資料

-(void)initdatasource

-(nsdate*)setlastmonthwithyear:(nsinteger)year andmonth:(nsinteger)month andday:(nsinteger)dayelse

return date;

}//請求資料

-(void)setmydayarraywithyear:(nsinteger)year andmonth:(nsinteger)month andday:(nsinteger)day

for (nsinteger i = 1; i <= dayrange.length ; i++)

for (nsinteger i = 1; i <= (7 - lastday.weekday); i++)

}//**方法

-(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section

-(nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview

- (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath

-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath

//調整item的位置 使item不緊挨著螢幕

- (uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout insetforsectionatindex:(nsinteger)section

//設定水平間距與豎直間距 預設為10

- (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout minimuminteritemspacingforsectionatindex:(nsinteger)section

- (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout minimumlinespacingforsectionatindex:(nsinteger)section

@end

#import "viewcontroller.h"

#import "thccalendar.h"

#import "collectionviewcell1.h"

#define width [uiscreen mainscreen].bounds.size.width

#define height [uiscreen mainscreen].bounds.size.height

@inte***ce

viewcontroller ()

@property (weak, nonatomic) iboutlet

uilabel *nowmouth;

@property (nonatomic,strong)thccalendar * calendar;

@end

@implementation

viewcontroller

- (void)viewdidload

-(void)initcollectionview

- (ibaction)nextclick:(uibutton *)sender

- (ibaction)lastclick:(uibutton *)sender

web頁面控制項之日曆控制項

web頁面開發中一般需要引用日曆,如根據乙個日期或時間,或者根據乙個日期範圍或時間範圍,查詢業務資料。下面介紹一下使用日曆控制項的使用。1.頁面中引入構件的相關js庫 樣式 2.頁面中引用日曆控制項 前後時相 id beforedate value nf cus wdatepicker class ...

iOS日曆控制項

專案需要,前一陣子重構了下ipad工程,新增了乙個滾動無縫日曆。當時沒有頭緒,網上找了乙個原始碼改吧改吧就上線了 參考鏈結 這個功能很多而且流暢性也特別好,推薦不會寫的可以參考下。這幾天,活不太忙就把日曆控制項裁剪了下,做個最簡單的滾動無縫日曆。效果如下圖 日曆可以左右滾動,點選某個日期後會變色,並...

HTML5之日曆控制項

html5定義了幾個與日期有關的新控制項。支援日期控制項的瀏覽器會提供乙個方便的下拉式日曆,供使用者選擇。以下測試和截圖都是在谷歌瀏覽器完成的,其他瀏覽器可能略有差異。js操作 獲取日期控制項物件 var otimer document.getelementbyid mytime console.l...