When the collectionView is too high or too wide,a lot of cell maybe be created

When I set like this:
Code Block swift
 collectionView.frame = .init(x: 0, y: 0, width: 3000, height: 100)


a lot of cell will be created...But need the collectionView to be wide like this..So I can't let collectonView 's width is as wide as controller's view 's width. So I set it to 3000 (maybe more wide actually..).In this case,a lot of cell will be created and if width is larger than contentSize.width ..the cell's recycle system will be useless...

So ,How can i let collectionView wide like this can just create the cell's I can see?
When the collectionView is too high or too wide,a lot of cell maybe be created
 
 
Q