礼物墙适配修改

This commit is contained in:
chenshuanglin
2023-03-21 15:12:13 +08:00
parent 3358f0c68e
commit 7ba4fbd7b8
3 changed files with 11 additions and 7 deletions

View File

@@ -49,9 +49,10 @@
make.edges.mas_equalTo(self.contentView); make.edges.mas_equalTo(self.contentView);
}]; }];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(55, 55)); make.left.mas_equalTo(7);
make.right.mas_equalTo(-7);
make.top.mas_equalTo(2); make.top.mas_equalTo(2);
make.centerX.mas_equalTo(self.contentView); make.height.mas_equalTo(self.giftImageView.mas_width);
}]; }];
[self.giftNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) { [self.giftNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {

View File

@@ -92,9 +92,10 @@
if (indexPath.section == 0) { if (indexPath.section == 0) {
return 133; return 133;
} else if(indexPath.section == 1) { } else if(indexPath.section == 1) {
CGFloat itemHeight = 82; CGFloat itemWidth = (CGRectGetWidth(self.view.frame) - 20*2 - 16*3)/4.0;
CGFloat itemHeight = 82.0/72.0*itemWidth;
CGFloat topHeight = 100; CGFloat topHeight = 100;
return itemHeight * 3 + 12 * 2 + topHeight + 25; return itemHeight * 3 + 14 * 2 + topHeight + 25;
} else { } else {
return 0; return 0;
} }

View File

@@ -46,7 +46,9 @@
} }
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource #pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.datasource.count > 0? CGSizeMake(72, 82) : CGSizeMake(KScreenWidth - 30, 82 * 3 + 12*2); CGFloat width = (CGRectGetWidth(collectionView.frame) - 16*3)/4.0;
CGFloat height = 82.0/72.0*width;
return self.datasource.count > 0? CGSizeMake(width, height) : collectionView.bounds.size;
} }
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
@@ -78,8 +80,8 @@
- (UICollectionView *)collectionView{ - (UICollectionView *)collectionView{
if (!_collectionView) { if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = (KScreenWidth - 20 *2 -72 * 4) / 3.0;; layout.minimumInteritemSpacing = 16;
layout.minimumLineSpacing = 12; layout.minimumLineSpacing = 14;
// layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10); // layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self; _collectionView.dataSource = self;