Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. class MonthCalendarCell: UICollectionViewCell {
  2. var dateLabel: UILabel?
  3.  
  4. func addDateLabel(label: UILabel) {
  5. self.dateLabel = label
  6. self.addSubview(label)
  7. }
  8. }
  9.  
  10. override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
  11. let calendarFlowLayout = CalendarFlowLayout()
  12.  
  13. super.init(frame: frame, collectionViewLayout: calendarFlowLayout)
  14.  
  15. self.dataSource = self
  16. self.delegate = self
  17. self.registerClass(MonthCalendarCell.self, forCellWithReuseIdentifier: self.identifier)
  18.  
  19. // TODO: work on this
  20. self.backgroundColor = UIColor.groupTableViewBackgroundColor()
  21. }
  22.  
  23. func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  24. let cell = collectionView.dequeueReusableCellWithReuseIdentifier(self.identifier, forIndexPath: indexPath) as MonthCalendarCell
  25.  
  26. let label = UILabel()
  27. label.text = "1"
  28. label.frame = CGRectMake(0, 0, cell.bounds.width, cell.bounds.height)
  29. label.textAlignment = NSTextAlignment.Center
  30. label.backgroundColor = UIColor.redColor()
  31.  
  32. self.highlightView(label)
  33.  
  34. cell.addDateLabel(label)
  35.  
  36. return cell
  37. }
  38.  
  39. func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
  40. let cell = collectionView.dequeueReusableCellWithReuseIdentifier(self.identifier, forIndexPath: indexPath) as MonthCalendarCell
  41. println(cell.dateLabel!)
  42. }
  43.  
  44. class MonthCalendarCell: UICollectionViewCell {
  45. var dateLabel: UILabel? {
  46. get {
  47. return self.dateLabel
  48. }
  49.  
  50. set(label) {
  51. self.addSubview(label!)
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement