ios - UICollectionView spacing is incorrect every other row -
i creating custom flow layout uicollectionview, , trying spacing right. despite setting minimumlinespacing = 2
every other line, there 1px between each row of images, can seen here. believe because apple uses points instead of pixels, how fix this? here code in collectionviewcontroller sets flow layout:
let screenwidth = self.collectionview?.bounds.size.width let flowlayout: uicollectionviewflowlayout = uicollectionviewflowlayout() flowlayout.minimuminteritemspacing = 2 flowlayout.minimumlinespacing = 2 let totalspacing = flowlayout.minimuminteritemspacing * 4.0 let imagesize = (screenwidth!-totalspacing)/4.0 flowlayout.itemsize = cgsize(width: imagesize, height: imagesize)
i figured out. if height of cell repeating float, spacing between each row alternate, every other row. instance, if want fit 3 cells 2 points spacing between each one, each cell 123.6666666667 points wide on iphone 6. (an iphone 6 375 points across, leading calculation (375-4)/3 = 123.6666666667). if proceed use same value height width, last 2/3 of point cause rows' spacing alternate, seen here.
what i've found cell height not have int fix this; setting 123.5 solve problem, ints of course work.
Comments
Post a Comment