UICollectionView Strange gap between cells (Swift) -
i'm trying display 2 sections of images in columns of 3. reason, there these strange gaps between of cells. i've looked everywhere in storyboard , seems correct. i've experimented setting columns 2, 4, 5, 6, , on. there no strange white lines columns set other number. these lines appear both in 5s simulator , on physical iphone 5s.
override func viewdidload() { super.viewdidload() let width = cgrectgetwidth(collectionview!.frame) / 3 let layout = collectionviewlayout as! uicollectionviewflowlayout layout.itemsize = cgsize(width: width, height: width) }
this error being caused floating point calculation did width
.
an iphone 5s has 320 pixels on width. assuming collectionview
has same width screen, width , height of each cell 320 / 3 = 106.666666667
, repeating decimal.
to fix this, i'd recommend using number divisible 3, , smaller (and close to) 320 collectionview
width. if use 318, resulting width , height of each cell 318 / 3 = 106
, nice number!
general rule: uicollectionview width should divisible number of cells in each row.
Comments
Post a Comment