でサイズのセルを、私はsomeObjの値にもよるが異なるアスペクト比を持つように私の細胞を希望どのようにGridViewの
class ListViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
private var collection: ACollection?
private var collectionViewLayout:UICollectionViewFlowLayout?
override func loadView() {
super.loadView()
collectionViewLayout = UICollectionViewFlowLayout()
collectionViewLayout?.itemSize.width = 128
collectionViewLayout?.itemSize.height = 227
view = UICollectionView(frame: CGRect.zero, collectionViewLayout: collectionViewLayout!)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let someObj: SomeObj = collection!.getObject(index: indexPath.item)
let cell: UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(UICollectionViewCell.self), for: indexPath as IndexPath)
let cellView: UIImageView = UIImageView(image: object.image)
cellView.frame = cell.bounds
cell.contentView.addSubview(cellView)
return cell
}
次のようになりますgridlistを持っています。それらを重ならないでどのようにセルのサイズを変更できますか?私はしようとしました
cellView.frame = CGRect(x:0,y:0,width:100,height:300)
cellView.frame =cell.bounds
しかし、細胞が重なっています。
'UICollectionViewDelegateFlowLayout'に' collectionView(、layout:sizeForItemAt:) '関数を実装するべきだと思います。フローレイアウトを使用しているようです。 – sCha
@sChaそれはいくらか動作します。私が見ているのは、サイズを変更すると古いサイズのセルを描画し、別のサイズのセルを上に描画することです。 – user2175783