ios - Collection View vertical padding issue -


i making collection view horizontally scrolled. collection view in uitableview cell
collection view image

my height of collection view 170
making cell of 75x75

-(uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout insetforsectionatindex:(nsinteger)section; return uiedgeinsetsmake(4, 5, 6, 3); } 

this inset setting. padding top 4 left 5 right 3 , bottom 6. collection view has 20 items horizontally scrolled. problem vertical spacing of items when 2 rows made. want keep minimum. used this

- (cgfloat)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout minimumlinespacingforsectionatindex:(nsinteger)section {     return 2.5; } 

it provided 2.5 padding between various items still vertical padding can see image vertical space between 2 lines of images around 10. want decrease 2.5. did change in return uiedgeinset if increase padding bottom, collection view makes single row dont want. example if use this

-(uiedgeinsets)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout insetforsectionatindex:(nsinteger)section{ return uiedgeinsetsmake(4, 5, 7, 3); } 

i output
wrong output

how overcome problem. want equal , minimum spacing between items. square (75x75). appreciated. thanks

use following code set height of collection view cell.

func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout,sizeforitematindexpath indexpath: nsindexpath) -> cgsize{               var collectionviewheight = collectionview.fram.size.height                  let cellheight = collectionviewheight/2 - 5                 return cgsize(width: cell height , height: cellheight)          } 

now calculate height of collection view , divide 2 if have fix 2 number of rows , and subtract 5 each collectionviewheight 170 , divide 2 85 , - 5 80 height every cell , width equal square cell

this fit view else if can change values according requirement


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -