1

I made a custom UIView in a xib and loaded as :

class func instanceFromNib() -> ExclusiveCollectionView {
    return UINib(nibName: "ExclusiveCollectionView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! ExclusiveCollectionView
}

The custom view also got a subview - UIcollection view object. Now when I tried to load in the parent which contains a stack view. In parent controller, viewWillAppear

    let customView  = ExclusiveCollectionView.instanceFromNib()
    myStackView.addArrangedSubview(customView)

The custom view always stays with Frame Rectangle frame. For instance frame rectangle width in xib is 320 for iphone 5s, then after loading in stackview view still stays in 320 instead of 414 for iPhone 8 Plus.

iPhone 5S :

enter image description here

iPhone 8 Plus :

enter image description here

I know this is a common issue, already solved by SO champs. But anyhow I am not able to find the working solution. I am using Swift 4.1 with XCODE 9.0.1 tested in iPhone 5S and iPhone 8 Plus.

//Update : I tried to add after updating frame in viewDidLayoutSubview as given in many SO answers. But it is not working.

I have created a gist for the same questions for more clarity.

byJeevan
  • 3,728
  • 3
  • 37
  • 60
  • Try implementing sizeForItemAtIndexPath function of collectionview flow layout. – shivi_shub Jul 21 '18 at 18:24
  • @shubham I have already tried with sizeForItemAtIndexPath delegate, gives same result because... the problem is with customview+collectionview frame, which is essentially used to calculate the cell items size. – byJeevan Jul 22 '18 at 03:45
  • Is this problem with the way loading XIB ? – byJeevan Jul 23 '18 at 05:49

0 Answers0