2016-05-04 9 views
1

私はカレンダーをカスタマイズするためにMBCalendarKitを使用しています。各カレンダーセルのテキストラベルに追加したい。参考のためにgithub "https://github.com/MosheBerman/MBCalendarKit"のサンプルコードをダウンロードしてください。MBCalendarKitのカレンダーセルコンテンツにラベルを追加する方法は?

編集:

私はループのために使用される複数のラベルを作成します。どうしましたか?

NSMutableArray *dateButtons = [NSMutableArray array]; 
    for (NSInteger i = 1; i <= 42; i++) { 
     DateButton *dateButton = [DateButton buttonWithType:UIButtonTypeCustom]; 
     dateButton.calendar = self.calendar; 
     [dateButton addTarget:self action:@selector(_dateButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 

     UILabel *travelTime = [[UILabel alloc] initWithFrame:CGRectMake(3, 23, 20, 20)]; 
     travelTime.font=[travelTime.font fontWithSize:9]; 
     [travelTime setTextColor:[UIColor blueColor]]; 
     travelTime.text = @"9"; 

     UILabel *workTime = [[UILabel alloc] initWithFrame:CGRectMake(30, 23, 20, 20)]; 
     workTime.font=[workTime.font fontWithSize:9]; 
     [workTime setTextColor:[UIColor orangeColor]]; 
     workTime.text = @"9"; 

     [dateButton addSubview:travelTime]; 
     [dateButton addSubview:workTime]; 
     [dateButtons addObject:dateButton]; 
    } 
self.dateButtons = dateButtons; 
+0

の作者だそれは質問や答えますか? – rptwsthi

答えて

0

あなたがMBCalendarKitの古いバージョンを使用している場合は、おそらく、細胞の内部でカスタムコンテンツを表示するには、直接CKCalendarCellクラスを変更する必要があると思います。

MBCalendarKit 5には、カスタムコンテンツをセルに追加するための変更が加えられています。独自のコードでCKCustomCellProviderプロトコルを実装します。実装する必要があるのは2つの部分です:

  1. customCellClassメソッド。
  2. calendarView:willDisplayCell:inContext:メソッド。あなたはカスタムUICollectionViewサブクラスを作成し、customCellClassからそのクラスを返すべきであるため、その後、自分自身で元のセルの内容を置き換えにしたい場合は

。 CalendarViewの内部:willDisplayCell:inContext:セルを自動レイアウト制約で設定します。 willDisplayCell:inContext:あなたはデフォルトのセルの内容を変更したい場合は

、あなたはその後、calendarViewをcustomCellClassからCKCalendarCell.classを返す、とすることができますあなたが望むように変更するために、デフォルトのセルのインスタンスを、販売します。

免責事項:私はMBCalendarKit

関連する問題