给UICollectionView添加头部headerView

2022-04-29  本文已影响0人  不要虚度美好的时光
{
......
        myCollectCollectionView.contentInset = UIEdgeInsets(top: 120, left: 0, bottom: 0, right: 0)
        
        let headerLable = UILabel(frame: CGRect(x: 0, y: -120, width: SCREEN_WIDTH, height: 120))
        myCollectCollectionView.addSubview(headerLable)
        headerLable.isUserInteractionEnabled = true
        headerLable.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tap)))
        headerLable.text = "My Header"
        headerLable.textAlignment = .center
//        head.backgroundColor = UIColor.red

}
    @objc func tap(){
        print("tap")
    }

给UICollectionView添加头部视图headerView

上一篇下一篇

猜你喜欢

热点阅读