-2

I am using a Horizontal CollectionView and UIButton embedded inside a Horizontal StackView. Button has a fixed Height and Width (say 50 X 50 )I want Stackview Width to be dynamic according to CollectionView contentsize. Please guide me through this.

This is what I am Getting

This is what i want to Achieve

StackView Width should grow dynamially

TMirza
  • 47
  • 5

2 Answers2

0

Can't you add "+" button as last cell of CollectionView and set background color to orange for other cells? I think it will be easier.

Nexus
  • 560
  • 1
  • 4
  • 9
  • I can Add But As per the requirement, depending on number of cells, collectionview should scroll horizontally provided button should remain at fixed position at last – TMirza Oct 30 '19 at 07:56
  • So, by adding button at last it will be remain at the end of all cells. As per my knowledge, its not possible to do only via a stackView. – Nexus Oct 30 '19 at 08:04
0

Better way is to add cell in the last index of UICollectionView.

Here is the implementation

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
   return COUNT + 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    if indexPath.row = COUNT{
      return PLUSCELL
    }else{
      return NORMALCELL
    }

}
Taimoor Suleman
  • 1,588
  • 14
  • 29