Signo Signo - 1 month ago 8x
Objective-C Question

Unable to create bottom border on UICollectionView Cell

I need to add a 1px bottom border to my UICollectionView cells but I can't get it working, I tried the following code but the border doesn't show:

- (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;

What could be the problem?

CGRectMake gets (x,y,width,height) as parameter so I can't understand what's wrong on my code


You need to have correct y offset

//create the border
    UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - 1, cell.frame.size.width, 1)];
    bottomBorder.backgroundColor = [UIColor redColor];