1

Piggy backing off this SO question,

If I change

 cell.layer.borderWidth = 0.0

it removes the border from the top and bottom of the cell but won't remove the left and right borders. http://imgur.com/c2oDzjc Is there anyway of removing all borders and cell spacing so that the image is completely flush? My code:

var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 0

}

func collectionView(collectionView: UICollectionView,
    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! CollViewCell
    //cell.imageCell.image = UIImage(named: self.gridIMages[indexPath.row])

    cell.backgroundColor = UIColor.whiteColor()
    cell.layer.borderColor = UIColor.blackColor().CGColor
    cell.layer.borderWidth = 0.0
    cell.frame.size.width = screenWidth / 3
    cell.frame.size.height = screenHeight / 3

    return cell
}
Community
  • 1
  • 1
duyn9uyen
  • 7,733
  • 12
  • 36
  • 47

1 Answers1

2

You aren't assigning your layout anywhere. You just create it and don't use it.

So you need collectionView.collectionViewLayout = layout in the viewDidLoad. But it might be easier to just set it in interface builder.

Stefan Salatic
  • 4,273
  • 3
  • 20
  • 30
  • Thanks for catching that! So adding that line removed the 1st column border. But the second one still exists. http://imgur.com/ISEyl3i – duyn9uyen Apr 27 '15 at 17:18
  • 1
    Try to print out the cell width for each cell. It might happen that the width is 320, and that all of the cells are 106. And then you have two pixels missing (although I am just wildly guessing). Also always use collectionView.frame.width, instead of ScreenWidth. In your case it will be the same, but if you decide to resize the collectionView later your code won't work, and this will. – Stefan Salatic Apr 28 '15 at 08:25