前言
我們項(xiàng)目最近需要寫(xiě)一個(gè)日歷的功能凌彬,我在這之前也是沒(méi)有寫(xiě)過(guò)這個(gè)。然后自己就去查API最楷,去看別人的講解整份。貌似通了一些待错,又貌似沒(méi)通。哈哈烈评,把我寫(xiě)的我們的最初定的實(shí)現(xiàn)效果拿出來(lái)火俄,大家如果有需要可以看一下。自己寫(xiě)一下讲冠,不要做拿來(lái)黨瓜客,不然到時(shí)候如果運(yùn)行有錯(cuò)誤,你改都不知道去哪修改竿开。
思想
其實(shí)日歷比較好寫(xiě)的谱仪,因?yàn)樘O(píng)果已經(jīng)把你所需要的API都給你提供了,你只需要調(diào)用就行了否彩。我個(gè)人感覺(jué)只是在把當(dāng)月天數(shù)排布的時(shí)候麻煩一點(diǎn)點(diǎn)疯攒,我個(gè)人采用一個(gè)數(shù)組加載所有的數(shù)據(jù)的形式去展示。當(dāng)然八仙過(guò)海列荔,各顯神通敬尺,這個(gè)看個(gè)人的理解。 我的排布代碼:- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CalenderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CALENDER forIndexPath:indexPath];
if (indexPath.section == 0) {
cell.dateLabel.text = timerArray[indexPath.row];
cell.dateLabel.font = [UIFont systemFontOfSize:14];
cell.dateLabel.textColor = [UIColor colorWithRed:1.0
green:0.0
blue:0.0
alpha:0.495803420608108];
}else{
cell.dateLabel.textColor = [UIColor colorWithRed:0.0
green:0.0
blue:0.0
alpha:0.495803420608108];
//獲得本月第一天在星期幾
allDayArray = [NSMutableArray array];
NSInteger day = [self currentFirstDay:_date];
for (NSInteger i = 0; i < day; i++){
[allDayArray addObject:@""];
}
NSInteger days = [self currentMonthOfDay:_date];
for (NSInteger i = 1; i <= days; i++) {
[allDayArray addObject:@(i)];
}
//把剩下的空間置為空
for (NSInteger i = allDayArray.count; i < 42; i ++) {
[allDayArray addObject:@""];
}
cell.dateLabel.text = [NSString stringWithFormat:@"%@",allDayArray[indexPath.row]];
}
return cell;
}
運(yùn)行結(jié)果:
結(jié)束
至此結(jié)束肌毅,哈哈? ? ? 忘了說(shuō)了筷转,如果各位看客看著有用,請(qǐng)給個(gè)小星星悬而,謝了呜舒。