gpt4 book ai didi

ios - collectionView 单元格重叠

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:42 24 4
gpt4 key购买 nike

我正在尝试创建具有 4 种不同类型的多个 collectionViewCells。每个细胞对这 4 种类型中的一种都有不同的看法。这些类型的每个 View 都可以根据用户选择具有不同的内容。

我遇到的问题是,当屏幕上出现多个相同类型的 View /单元格时,某些卡片会重叠/无法正确加载。

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Card *card = [[[usermanager getSelectedUser] getCards] objectAtIndex:indexPath.item];
NSLog(@"CARD LOADING: %@", card.title);
[card setupLayout];
UICollectionViewCell *cell;
if(card.type.intValue == 1){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"lifestyleCell" forIndexPath:indexPath];
}else if(card.type.intValue == 2){
cell= [collectionView dequeueReusableCellWithReuseIdentifier:@"sceneCell" forIndexPath:indexPath];
}else if(card.type.intValue == 3){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"energyCell" forIndexPath:indexPath];
}else if(card.type.intValue == 4){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"productCell" forIndexPath:indexPath];
}else{
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cardCell" forIndexPath:indexPath];
}
[cell addSubview:card];

//Add dropshadow
cell.contentView.layer.borderWidth = 1.0f;
cell.contentView.layer.borderColor = [UIColor clearColor].CGColor;
cell.contentView.layer.masksToBounds = YES;

cell.layer.shadowColor = [UIColor blackColor].CGColor;
cell.layer.shadowOffset = CGSizeMake(0, 5.0f);
cell.layer.shadowRadius = 2.0f;
cell.layer.shadowOpacity = 0.5f;
cell.layer.masksToBounds = NO;

return cell;
}

卡片是我添加到单元格的 View 。如上所述,这些卡片有多种类型。

最佳答案

尝试使用:

cell.clipsToBounds = YES;

关于ios - collectionView 单元格重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29817770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com