【发布时间】:2021-06-14 14:32:54
【问题描述】:
我正在尝试在目标 c 的每一行创建一个包含 3 个项目的集合视图。这是我的代码:
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return items.count;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
collectionView.backgroundColor = [UIColor clearColor];
NSString* buf = items[indexPath.row];
CollectionCell *cell = (CollectionCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
[cell loadCell:buf];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIColor *leftColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.5];
cell.layer.cornerRadius = ((screenBounds.size.width)*0.25)/2;
cell.layer.borderColor = leftColor.CGColor;
cell.layer.borderWidth = 2;
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat boxWidth;
boxWidth = ((screenBounds.size.width)*0.25);
bottomSpacing = 17;
return CGSizeMake(boxWidth, boxWidth);
}
我做错了什么,是否可以修复它?
【问题讨论】:
标签: ios objective-c xcode