Posts

Showing posts with the label uicollectionview

How to display 3 cells per row in UICollectionView?

Image
Clash Royale CLAN TAG #URR8PPP How to display 3 cells per row in UICollectionView? I used a custom flow layout according to this post. Here is my implementation: @implementation CustomLayout -(void)prepareLayout{ [super prepareLayout]; // [self invalidateLayout]; if(self.collectionView){ CGSize newItemSize=self.itemSize; // Number of items per row int itemsPerRow=3; float totalSpacing=self.minimumLineSpacing*(itemsPerRow-1); newItemSize.width=(self.collectionView.bounds.size.width -totalSpacing)/itemsPerRow; if(self.itemSize.height>0){ float itemAspectRatio=self.itemSize.width/self.itemSize.height; newItemSize.height=newItemSize.width/itemAspectRatio; } [self setItemSize:newItemSize]; } } @end This is what I've got: What did I miss? I've come across some other SO posts but no luck so far. 4 Answers 4 Swift 3.0. Works for both horizontal and v...

Image does not fit properly in collectionCell

Image
Clash Royale CLAN TAG #URR8PPP Image does not fit properly in collectionCell In Swift 3. My app has a table view and a detail view with is a view controller. Here I added a collection view. An array of images must be presented. The images adapt themselves beautifully if in portrait I check the content mode in scaler to fill. In ladscape it works in aspectFill. Vice-versa, the layout does not fit. I did the following in cellForItem At: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = myCollection.dequeueReusableCell(withReuseIdentifier: "cellCollection", for: indexPath) as! CollectionViewCell cell.cellImage.image = UIImage(named: array[indexPath.item]) if UIDevice.current.orientation.isLandscape{ cell.cellImage.contentMode = .scaleAspectFill } else if UIDevice.current.orientation.isPortrait{ cell.cellImage.contentMode = .scaleToFill } return cell } I...

UICollectionView with full page cells VS UIScrollView with child view controllers

Image
Clash Royale CLAN TAG #URR8PPP UICollectionView with full page cells VS UIScrollView with child view controllers I'm trying to create a ViewController which would have swipe-able (android like tabs) pages. These pages themselves will have scrollviews(vertical) inside them and multiple views which would be added dynamically depending on type of response (different network calls for each page). I can't use a PageViewController as I want the pages to take up only half the screen. Issues with CollectionView - Issues with ScrollView - PS - data in each page would be 4-10 stackviews each containing 2-10 images/labels OR just one collectionview PSS - Total number of tabs wouldn't exceed 10, minimum would be 1 Have you thought about using CoreData to keep track of the data you'd like? – Nickolans yesterday ...