我的最好的办法,以解决这个问题是以某种方式告诉每一个细胞,如果它是一节或一排最后一个单元格的最后一排;那么单元格会关闭有问题的边界,部分标题会绘制顶部边框以及底部,并且所有内容都将变得浑浊。不过,我不知道如何实现这一点。
你所描述的或多或少是我在类似场景中所做的。我添加了一个边界属性,我的手机:
typedef NS_OPTIONS(NSInteger, TLGridBorder) {
TLGridBorderNone = 0,
TLGridBorderTop = 1 << 0,
TLGridBorderRight = 1 << 1,
TLGridBorderBottom = 1 << 2,
TLGridBorderLeft = 1 << 3,
TLGridBorderAll = TLGridBorderTop | TLGridBorderRight | TLGridBorderBottom | TLGridBorderLeft,
};
@interface TLGridCellView : UIView
@property (nonatomic) TLGridBorder border;
@end
然后,我将边框设置为我的视图控制器的电池配置:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TLGridCellView *cell = ...;
if (indexPath.item == self collectionView:collectionView numberOfItemsInSection:indexPath.section - 1) {
cell.border = TLGridBorderLeft;
} else {
cell.border = TLGridBorderLeft | TLGridBorderRight;
}
return cell;
}
我最终做了一件很喜欢这样 - 我只要我把它变成一个要点在这里发表一个答案,所以我可以分享。 –