collectionViewCellを3つ縦に配置しています。
(グリーン,パープル,グレー)
グレーのみ、scrollDirection = .horizontalを適応したいのですが、
override viewDidLoad内で私が定義すると3つ全てのセルが.horizontalの動きになってしまいます。
numberOfItemsInSectionなどの関数ではセルをif文のsectionで切り分けているので、
新たに関数を使い、if文のsectionでグレーのみにscrollDirectionを適応する方法を調べているのですが、
分からずにいます。
教えて頂ければ助かります。
よろしくお願いします。
追記しました。
//コントローラーです import UIKit class HogeController: UICollectionViewController, UICollectionViewDelegateFlowLayout { let cellId3 = "cellId" let cellId2 = "cellId" let cellId = "cellId" override func viewDidLoad() { super.viewDidLoad() collectionView?.backgroundColor = .white let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.minimumLineSpacing = 0 layout.minimumInteritemSpacing = 0 collectionView?.register(CCCCell.self, forCellWithReuseIdentifier: "cellId3") collectionView?.register(BBBCell.self, forCellWithReuseIdentifier: "cellId2") collectionView?.register(AAACell.self,forCellWithReuseIdentifier: "cellId") } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch indexPath.section { case 2: return collectionView.dequeueReusableCell(withReuseIdentifier: "cellId3", for: indexPath) as! CCCCell case 1: return collectionView.dequeueReusableCell(withReuseIdentifier: "cellId2", for: indexPath) as! BBBCell default: return collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! AAACell } } override func numberOfSections(in collectionView: UICollectionView) -> Int { return 3 } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if section == 2 { return 10 } else { return 1 } } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { switch indexPath.section { case 2: return CGSize(width: 50, height: 50) case 1: return CGSize(width: view.frame.width, height: 200) default: return CGSize(width: view.frame.width, height: 200) } } }
//ホリゾンタルにしたいグレーのCCCCellです。 import UIKit class CCCCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) setupMenuBar() backgroundColor = .gray } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupMenuBar() { } }
//
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/19 04:24 編集
2018/04/19 11:07
退会済みユーザー
2018/04/19 12:27
2018/04/19 21:26
退会済みユーザー
2018/04/20 03:53 編集
2018/04/20 11:38
退会済みユーザー
2018/04/22 15:39 編集