おっしゃる通り、CalendarCellのメンバがtextlablしかいないので追加する必要がありますね。追加後はセルのインスタンスからcell.dayのようにアクセスできるようになります。
swift
1class CalendarCell: UICollectionViewCell {
2 var textLabel : UILabel!
3 var day :Int! // 日付
4
5 required init?(coder aDecoder: NSCoder) {
6 super.init(coder:aDecoder)!
7
8 //UILabelを生成
9 textLabel = UILabel(frame: CGRect(x:0, y:0, width:self.frame.width, height: self.frame.height))
10 textLabel.font = UIFont(name: "HiraKakuProN-W3", size: 12)
11 textLabel.textAlignment = NSTextAlignment.center
12
13 // Cellに追加
14 self.addSubview(textLabel!)
15 }
16
17 override init(frame: CGRect) {
18 super.init(frame: frame)
19
20 }
21}
22
ViewController.swift
swift
1 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
2
3 //コレクションビューから識別子「CalendarCell」のセルを取得する
4 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! CalendarCell
5 if(indexPath.section == 0){ //曜日表示
6 cell.backgroundColor = UIColor.green
7 cell.textLabel.text = weekArray[indexPath.row]
8 cell.day = 0 // 曜日にはとりあず0を入れとく
9
10 }else{ //日付表示
11 cell.backgroundColor = UIColor.white
12 cell.textLabel.text = ""
13 cell.day = indexPath.row + 1 // 日付
14 }
15 return cell
16 }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/08 12:25
2016/12/09 07:26
2016/12/09 09:32
2016/12/10 09:42