最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中给UICollectionViewCell的下面添加一个label文字:Supplement或者footer

Swift crifan 3600浏览 0评论

之前已经实现了:

[已解决]swift实现等分的UI界面组建视图

但是却了cell下面的字:

需要把下面加上名字。

搜:

swift uicollectionview supplementary

Use Supplementary View to Add Header and Footer in UICollectionView

viewForSupplementaryElementOfKind

指的是:

section的header和footer

不是我要的

突然想起来了:

此处的cell,内部自己添加一个 name的label就好了啊。。。

代码:

    let paddingY:CGFloat = 8
    let nameLabelHeight:CGFloat = 16

        self.flowLayout = UICollectionViewFlowLayout()
        self.flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
       
self.flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20)
       
self.flowLayout.itemSize = CGSizeMake(SizeConversationTableViewCellImage,
           
SizeConversationTableViewCellImage + paddingY + nameLabelHeight)

        self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: flowLayout)
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
       
print("ConversationManageViewController cellForItemAtIndexPath")

        let cell:UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(StrIdConversationManageCollectionViewCell, forIndexPath: indexPath)
       
       
//for debug
        cell.backgroundColor = UIColor.yellowColor()

        let cellImage:UIImage = memberList[indexPath.row].headerImageLarge
//        let imageView:UIImageView = UIImageView(image: cellImage)
        let imageView:UIImageView = UIImageView(image: cellImage)
//        imageView.center = cell.contentView.center
        imageView.center.x = cell.contentView.center.x
        cell.
contentView.addSubview(imageView)
       
       
if (indexPath.row == 0) {
           
let nameLabelFrame = CGRectMake(0, cellImage.size.height + paddingY, cellImage.size.width, nameLabelHeight)
           
let nameLabel:UILabel = UILabel(frame: nameLabelFrame)
            nameLabel.
text = self.curPersonContactItem.name
            nameLabel.
textAlignment = NSTextAlignment.Center
            nameLabel.
font = UIFont.systemFontOfSize(12)
            cell.
contentView.addSubview(nameLabel)
           
           
//for debug
            nameLabel.backgroundColor = UIColor.greenColor()
        }
       

        return cell
    }

    

如下:

转载请注明:在路上 » [已解决]swift中给UICollectionViewCell的下面添加一个label文字:Supplement或者footer

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.206 seconds, using 22.16MB memory