Eth*_*anW 2 textlabel ios uicollectionview uicollectionviewcell swift
我有一个类文件,它是该类的子UICollectionViewController类。在我的cellForItemAtIndexPath方法中,我试图设置textLabel的单元格。但是,textLabel完成中没有选项。到目前为止,这是方法:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Configure the cell
cell.backgroundColor = cellColor ? UIColor.blueColor() : UIColor.orangeColor()
//cell.textLabel.text = "Text"???
switch indexPath.item {
case 0...5:
cellColor = true
case 6...13:
cellColor = false
default:
cellColor = true
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能将其添加textLabel到单元格中?
与tableViewCell不同,UICollectionViewCell没有textLabel。您需要将UILabel添加到单元格的内容视图示例中:
var title = UILabel(frame: CGRectMake(0, 0, cell.bounds.size.width, 40))
cell.contentView.addSubview(title)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5399 次 |
| 最近记录: |