本文介绍了如何将collectionview单元格扩展到全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试全屏打印图像我使用了 UICollectionViewDelegateFlowLayout这是我的代码
I'm trying to print the image on fullscreenI used UICollectionViewDelegateFlowLayouthere my code is
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemWidth = collectionView.bounds.width
let itemHeight = collectionView.bounds.height
return CGSize(width: itemWidth, height: itemHeight)
}
但它不会在全屏上显示内容,而是从顶部和底部留出空间
but it doesn't show the content on full screen it makes space from top and bottom
推荐答案
如果您想增加单元格大小以适应您的屏幕,您可以使用此方法.
If you want to increase cell size to fit to your screen you can use this method.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}
迅捷
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
//For entire screen size
let screenSize = UIScreen.main.bounds.size
return screenSize
//If you want to fit the size with the size of ViewController use bellow
let viewControllerSize = self.view.frame.size
return viewControllerSize
// Even you can set the cell to uicollectionview size
let cvRect = collectionView.frame
return CGSize(width: cvRect.width, height: cvRect.height)
}
这篇关于如何将collectionview单元格扩展到全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!