[英]How can custom collectionView cell?
我是Swift的新手。 我想使用UICollectionView創建一個簡單的填充詞應用程序。 當答案中有2個單詞(例如“ Hello World”)時,如何自定義UICollectionViewCell。 我希望“世界”將在下一行輸入。 並請告訴我如何使居中的單元格表示“你好”和“世界”居中? 感謝您的幫助。 這是我的代碼:
var arrayCharacter = ["H","E","L","L","O","W","O","R","L","D"]
extension QuestionVC: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrayCharacter.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "quizColCell", for: indexPath) as! QuizCollectionCell
cell.lblCharacter.text = arrayCharacter[indexPath.row]
return cell
}
}
我可以想到2種方式:
第一種方法 -考慮從以下位置重新設計數據:
var arrayCharacter = [“ H”,“ E”,“ L”,“ L”,“ O”,“ W”,“ O”,“ R”,“ L”,“ D”]。
至
var arrayWords = [“ HELLO”,“ WORLD”]
每個collectionViewCell將代表一個WORD。
每個單元格將為1行(全角)。在該單元格中,您將為每個字母創建標簽(並隱藏該單詞不使用的標簽)
第二種方式 ,通過使用SECTIONS(Google collectionView部分)。
數據必須是:
數組數組:
區段[0] = [“ h”,“ e”,“ l”,“ l”,“ o”]。
區段[1] = [“ w”,“ o”,“ r”,“ l”,“ d”]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.