Note that there are some explanatory texts on larger screens.

plurals
  1. POUICollectionView and Custom Height
    primarykey
    data
    text
    <p>i'm using a uiviewcontroller with inside a uicollectionvieww, and i searched on internet how i can customize the height of my total uicollectionview. For now i setup the uicollectionview with a height >= 1 (i'm using autolayout) Then in my .m file i tried with:</p> <pre><code>UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setItemSize:CGSizeMake(160, 160)]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; [flowLayout setMinimumInteritemSpacing:0]; [flowLayout setMinimumLineSpacing:0]; NSInteger itemCount = [self.collectionView numberOfItemsInSection:0]; [flowLayout setItemSize:CGSizeMake(self.collectionView.frame.size.width, 160 * itemCount)]; [self.collectionView setCollectionViewLayout:flowLayout]; NSLog(@"%f", self.collectionView.frame.size.height); </code></pre> <p>But in NSLog still show me the height to 1...how i can do for setup the height of my uicollectionview to a custom height(that is based on element in a section * 160). Any suggest ? Thanks.</p> <p><strong>EDIT:</strong> Where i create the cells:</p> <pre><code>-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { GalleryCell *cell = (GalleryCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCell" forIndexPath:indexPath]; NSDictionary *photo = [self.beachImages objectAtIndex:indexPath.row]; [cell.imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [photo objectForKey:@"original_url"]]] placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]]; return cell; } </code></pre> <p><strong>EDIT:</strong> Maybe the problem is that i use autolayout ? Here my constraints: <a href="http://cl.ly/image/2l0M432w0U1V" rel="nofollow">http://cl.ly/image/2l0M432w0U1V</a> <strong>EDIT:</strong> I tried with adding constraint by code:</p> <pre><code>[self.collectionView removeConstraints:self.collectionView.constraints]; NSLayoutConstraint *con1 = [NSLayoutConstraint constraintWithItem:self.collectionView attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:320]; [self.collectionView addConstraints:@[con1]]; </code></pre> <p>But not show my cells...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload