私はiOSとSwiftの両方が初めてです。コレクション ビューを作成しましたが、正常に動作しますが、複数のアイテムを 1 行に表示したいと考えています。試しましたが、うまくいきません。誰かが私を助けることができますか?前もって感謝します。
これは私のコードです:
ダッシュボードコレクションVC
import UIKit
class DashBoardCollectionVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var main_collection_view: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 8
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = main_collection_view.dequeueReusableCell(withReuseIdentifier: "identify_collection_cell", for: indexPath) as! DashboardCollectionViewCell
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var collectionViewSize = collectionView.frame.size
collectionViewSize.width = collectionViewSize.width/2.0 //Display Three elements in a row.
collectionViewSize.height = collectionViewSize.height/4.0
return collectionViewSize
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Item Clicked : \(indexPath.item)")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
}
}
このように見えます
ContainerView の設計
2つのアイテムを並べて表示したい。どうすればそれを達成できますか?