Note that there are some explanatory texts on larger screens.

plurals
  1. POWrong UICollectionViewCell size
    primarykey
    data
    text
    <p>I want to change size of my UICollectionViewCell</p> <p>In Interface Builder I set custom size</p> <p><img src="https://i.stack.imgur.com/sCyEZ.png" alt="enter image description here"></p> <p>In my code I want change size of cell</p> <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(274, 274); } </code></pre> <p>In future I need have different size of cell</p> <p>In my cell I have next method</p> <pre><code>- (void)awakeFromNib { backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height / 1.32)]; [self addSubview:backImageView]; lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, backImageView.height, self.width, self.height / 9.67)]; [self addSubview:lineImageView]; nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(28, lineImageView.originY + 5, self.width - 28, 15)]; nameLabel.font = [UIFont fontWithName:FontStyleBold size:14]; [self addSubview:nameLabel]; descriptLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.originX, lineImageView.originY + lineImageView.height + 3, nameLabel.width - nameLabel.originX, 25)]; descriptLabel.numberOfLines = 2; descriptLabel.font = [UIFont fontWithName:FontStyle size:8]; [self addSubview:descriptLabel]; self.backgroundColor = [UIColor whiteColor]; self.layer.masksToBounds = NO; self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(-1, 2.0, self.width + 2, self.height + 2) cornerRadius:0.f].CGPath; self.layer.shadowColor = [[UIColor blackColor] CGColor]; self.layer.shadowOpacity = .4f; self.layer.shadowRadius = 2.0f; } </code></pre> <p>In simulator I have next bad result</p> <p><img src="https://i.stack.imgur.com/6yLab.png" alt="enter image description here"></p> <p>If I set in Interface Builder size</p> <p><img src="https://i.stack.imgur.com/GZDfA.png" alt="enter image description here"></p> <p>In simulator all good</p> <p><img src="https://i.stack.imgur.com/uWa2t.png" alt="enter image description here"></p> <p>I thought that next method must change size of cell, but it change size of item</p> <pre><code>- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(274, 274); } </code></pre> <p>So how can I change size of UICollectionViewCell programmatically, without help of Interface Builder?</p>
    singulars
    1. This table or related slice is empty.
    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