1

I implement the UICollectionViewCell. Now I need to set border effect where the cell cross to each others like junction point.

here is the image, which I need to set border like this..

enter image description here

I tried out to give cell border but in output left & right side border is appear which is not my desired output. So my output look like this. (Wrong output)

enter image description here

So please help me..

NiravS
  • 1,144
  • 1
  • 12
  • 24
  • 2
    I think once you set UICollectionView background colour as per your boarder colour. May your problem will solved. Try it. – Yagnesh Dobariya Aug 18 '17 at 08:33
  • 1
    @YagneshDobariya I already check with changed background color, but when scrolling at that time background color is visible – NiravS Aug 18 '17 at 08:34
  • For that you can disable bounces effect in UICollection from Storyboard or programmatically. – Yagnesh Dobariya Aug 18 '17 at 08:36
  • are you trying to achieve a `parallax effect`? or just a `static border`. – Joe Aug 18 '17 at 10:42
  • @Joe Just static border.. – NiravS Aug 18 '17 at 11:16
  • can you explain your problem in short.its hard to understand your problem?. are you having problem with only outside border or post your tried code may help to solve your issue – Joe Aug 18 '17 at 11:21
  • I need to only set middle border '+' without outside border(Left&Right) – NiravS Aug 18 '17 at 11:23
  • can you post your collectionView frame size? – Joe Aug 18 '17 at 11:26
  • func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: CGFloat(collectionView.frame.size.width / 2 - 0.5 ), height: CGFloat(170)) } – NiravS Aug 18 '17 at 11:27
  • i mean frame size not contentSize.... – Joe Aug 18 '17 at 11:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152247/discussion-between-niravs-and-joe). – NiravS Aug 18 '17 at 11:31
  • Ya your code is working.. – NiravS Aug 18 '17 at 12:57

2 Answers2

1

Note: Below answer based on the discussion between question owner and myself.

You need to setup a collectionViewFlowLayout properly to achieve the desired output. Try below code:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    // All the values are changable according to your needs.
    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsets.zero
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 2
    return CGSize(width: (self.collectionView.frame.width / 2) - 1 , height:(self.collectionView.frame.height / 3) - 1)
}

Update 1: Calculating layout includes navigationBar and StatusBar.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    // All the values are changable according to your needs.
    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsets.zero
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 2
    return CGSize(width: (self.collectionView.frame.width / 2) - 1 , height:(((self.view.frame.height - ((navigationController?.navigationBar.frame.height)! + UIApplication.shared.statusBarFrame.height)) / 3) - 1))
}

You may need to validate collectionView frame in viewDidLayoutSubviews or viewWillLayoutSubviews

 override func viewDidLayoutSubviews() {
 collectionView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
}

Following link may help you to understand the collectionViewFlowLayout.

Enforce collectionView to have only 2 rows

uicollectionview remove top padding

Adjust cellsize for fit all screens?

Note: In future, Post your question with relevant code and state problem clearly.

Joe
  • 8,868
  • 8
  • 37
  • 59
0

setting border will not give the desired result. enter image description here

cgfloat intcellSize = ([[UIScreen mainScreen] bounds].size.width/3)-0.8;

now inside this method define it:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
 if ((mutArrContact.count%3) == 0) {

            return (mutArrContact.count/3) * intcellSize ;
        }
        else
        {
            return ((mutArrContact.count/3) * intcellSize)+ intcellSize;
        }

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    return CGSizeMake (intcellSize,intcellSize);
}

This is for displaing 3 cells with the desired result.

Divyesh Gondaliya
  • 884
  • 11
  • 21
Bhoomika
  • 26
  • 4