我需要1px的下边框添加到我的UICollectionView细胞,但我不能得到它的工作,我尝试下面的代码,但边框没有显示:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
cell.backgroundColor = [UIColor whiteColor];
cell.titolo.text = arrayt[prova];
//create the border
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height, cell.frame.size.width, 1)];
bottomBorder.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:bottomBorder];
return cell;
}
可能是什么问题呢?
CGRectMake得到(X,Y,宽度,高度)为参数的,所以我不明白什么是错在我的代码
最佳答案
你需要有正确的 y 偏移
//create the border
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - 1, cell.frame.size.width, 1)];
bottomBorder.backgroundColor = [UIColor redColor];
关于objective-c - 无法在 UICollectionView 单元格上创建底部边框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28834184/