koala2さん
こんにちは、実装したいのは恐らくメッセージアプリのようなもので思うのですが、その場合以下の実装はいかがでしょうか?
1、viewController作成
2、ViewContorller内にcollectionViewCellを作成
3、データーベースからメッセージをGETし、このcellに挿入する
import UIKit
Class MessageController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cellId")
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! UICollectionViewCell
return cell
}
//メッセージの数を記入
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
//cellのサイズ
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 50)
}
}
これが実装したい事がじゃなかったらすいませんw
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/16 01:28