2017-04-20 92 views
-2

我想在日期下的日曆上添加價格值。與以下圖片相同。iOS中的自定義日曆

enter image description here

我已經嘗試了許多第三方庫像FSCalendarJTCalendarawesome-ios-ui,但並沒有獲得成功呢。

是否有任何其他庫或解決方案。我想在日曆的日期下添加價格標籤。

任何幫助,將不勝感激。

+0

你用哪個庫? –

+1

使用FSCalendar: https://github.com/WenchaoD/FSCalendar –

+1

[這裏有很多](https://www.cocoacontrols.com/search?q=calendar) –

回答

1

我想你應該有部分的數量爲2定製UICollectionView使用,並在部分細胞的數量肯定是1 7和部分細胞的數量是42 使靜態數組這就是有周天名稱,比如 arrOfWeekDayName = [NSArray arrayWithObjects:@"SUN",@"MON", @"TUE", @"WED", @"THU", @"FRI", @"SAT", nil];

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView 
{ 
return 2; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
if (section == 0) 
{ 
    return arrOfWeekDayName.count; 
} 
else{ 
    return 42; 
    } 
} 

現在採取定製UICollectionViewCell一個作秀周天命名 和第二的顯示日期與獎品和任何你想要在你的顯示圖像。

例如我把兩個自定義UICollectionViewCell首先是weekCell和第二是dateCell

weekCell只有一個標籤,這是隻顯示天命名 和dateCell有三個屬性lblDatelblPrizeimgCell您根據您的要求增加。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
if (indexPath.section == 0) 
{ 
    weekCell *cell = (weekCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@「weekCell」 forIndexPath:indexPath]; 
    cell.lblDay.text =[arrOfWeekDayName objectAtIndex:indexPath.row]; 
    if (indexPath.row == 0) 
    { 
     cell.backgroundColor = [UIColor redColor]; 
    } 
    else 
    { 
     cell.backgroundColor = [UIColor colorWithRed:63.0/255.0f green:65.0/255.0f blue:70.0/255.0f alpha:1.0]; 
    } 
    return cell; 
} 
else 
{ 
    dateCell *cell = (dateCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@「dateCell" forIndexPath:indexPath]; 
    cell.lblDate.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12]; 
    cell.lblPrize.text= [NSString strngWithFormat:@「$5」]; 
    cell.imgCell.image = [UIImage imageNamed:@「myImage」]; 
return cell; 
} 
} 

時填寫一個月的價值,你需要這42個細胞 的所有值,並根據個月奶源該小區。 奶源細胞根據天背景顏色

FirstDateOfMonth = [CommonOps firstDayOfMonth:currentdate ]; 
    LastDateOfMonth = [CommonOps lastDayOfMonth:currentdate]; 
    if ([self date:date isEqualOrAfter:LastDateOfMonth]) 
    { 
     cell.lblDateTitle.textColor = [UIColor grayColor]; 
     cell.backgroundColor = [UIColor colorWithRed:209/256. green:209/256. blue:209/256. alpha:.5]; 
     cell.userInteractionEnabled = true; 
    } 
    else if ([self date: date isEqualOrBefore: FirstDateOfMonth]) 
    { 
     cell.lblDateTitle.textColor = [UIColor grayColor]; 
     cell.backgroundColor = [UIColor colorWithRed:209/256. green:209/256. blue:209/256. alpha:.5]; 
     cell.userInteractionEnabled = true; 
    } 
    else 
    { 
     cell.backgroundColor = [UIColor colorWithRed:243/256. green:221/256. blue:159/256. alpha:.5]; 
     cell.userInteractionEnabled = true; 
     if ([self date:currentdate isTheSameDayThan:date]) 
     { 
      ValueToDisplayOnHeaderFirstTime = indexPath.row; 
     } 
     cell.lblDateTitle.textColor = [UIColor blackColor]; 
    } 
    if (indexPath.row == 0 || indexPath.row == 7 || indexPath.row == 14 || indexPath.row == 21 || indexPath.row == 28|| indexPath.row == 35) 
    { 
     cell.backgroundColor = [UIColor colorWithRed:250/256. green:195/256. blue:181/256. alpha:.5]; 
     cell.lblDateTitle.textColor = [UIColor redColor]; 
    } 

在此,請讓我知道在評論部分

+0

不錯的解決方案,你可以詳細說明解決方案..... – madhuiOS

1

JTAppleCalendar可以建立這個給你(不要與JTCalendar混淆),如果你的任何混淆。

似乎有據可查。 簡單的設置。 如果該庫無法爲您創建日曆,那麼我會感到震驚。我在大約7分鐘內完成了我的日曆(完全設計)。

文檔發現Here

Cocoapod鏈接發現Here

Github上的鏈接發現Here