這裏是我的代碼:如何顯示集合視圖爲1行3列與RxSwift
import UIKit
import RxSwift
import RxCocoa
import RxOptional
class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let items = Observable.just(
(0..<20).map{ "Test \($0)" }
)
items.asObservable().bindTo(self.collectionView.rx.items(cellIdentifier: CustomCollectionViewCell.reuseIdentifier, cellType: CustomCollectionViewCell.self)) { row, data, cell in
cell.data = data
}.addDisposableTo(disposeBag)
}
}
所以如何顯示1行3列。
我找不到任何有關RxSwift集合視圖的教程。
嘗試增加CollectionViewCell – guru
嗨@guru的寬度,你知道如何做到這一點的代碼? – Khuong
FUNC的CollectionView(_的CollectionView:UICollectionView,佈局collectionViewLayout:UICollectionViewLayout,sizeForItemAt indexPath:IndexPath) - > CGSize { 回報CGSize(寬度:yourWidth,高度:yourHeight) } – guru