Home:ALL Converter>Swift: UICollectionView into UIViewController programmatically as subclass

Swift: UICollectionView into UIViewController programmatically as subclass

Ask Time:2015-08-17T14:13:03         Author:Oleg Popov

Json Formatter

I have a simple UIViewController and i want to place multiple UICollectionView (more than one) into that UIViewController programmatically.

enter image description here

I know this is entirely possible but i want to configure and implement the UICollectionView in subclass.

And the question is:

  • How can i init and add as subview UICollectionView in UIViewController
  • What type should be my subclass UICollectionView or UICollectionViewController

P.S. I don't use Storyboard or Nib and i want to do this 100% programmatically.

Thanks in advance

Author:Oleg Popov,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32043819/swift-uicollectionview-into-uiviewcontroller-programmatically-as-subclass
Ptah :

It should look like this:\n\nlet controller = <your UICollectionViewController initialization>\naddChildViewController(controller)\ncontroller.view.frame = CGRectMake(...) //frame of UICollectionView you want it takes in main View\nview.addSubview(controller.view)\ncontroller.didMoveToParentViewController(self)\n\n\nBy the way, it is actually much easier if you use the \"Container view\" in Interface Builder. Then you don't have to worry about any of these containment-related calls, and Interface Builder will take care of it for you.",
2015-08-17T07:35:19
yy