Rak*_*h.P 4 objective-c ios uicollectionview uicollectionviewlayout
我想构建一个类似于网格的集合视图布局。和
我尝试使用集合流布局,但它开始变得复杂。构建自定义布局对我来说似乎是更好的选择。
我面临的一些问题:-
关于如何处理的任何想法,
谢谢 :)
所以,我遇到了你同样的问题,我已经以这种方式解决了(快速示例)。
在此示例中,单元格绘制为正方形,2 列 x N 行。
class CustomViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
@IBOutlet var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self;
collectionView.dataSource = self;
}
//MARK: - Collection view flow layout delegate methods -
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let screenSize = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width
let cellSquareSize: CGFloat = screenWidth / 2.0
return CGSizeMake(cellSquareSize, cellSquareSize);
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(0, 0, 0.0, 0.0)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0.0
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0.0
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11962 次 |
| 最近记录: |