如何将 collectionview 单元格扩展到全屏
How to expand collectionview cell to full screen
我正在尝试全屏打印图像
我使用了 UICollectionViewDelegateFlowLayout
我的代码是
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)
}
但它不会全屏显示内容 space 从顶部和底部
如果您想增加单元格大小以适合您的屏幕,您可以使用此方法。
Objective-C
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}
Swift
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)
}
我正在尝试全屏打印图像 我使用了 UICollectionViewDelegateFlowLayout 我的代码是
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)
}
但它不会全屏显示内容 space 从顶部和底部
如果您想增加单元格大小以适合您的屏幕,您可以使用此方法。
Objective-C
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}
Swift
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)
}