PKCSwipeReusableView 0.1.1

PKCSwipeReusableView 0.1.1

测试已测试
语言 SwiftSwift
许可证 MIT
发布最新版本2017 年 7 月
SwiftSwift 版本3.0
SPM支持 SPM

pikachu987 维护。



  • pikachu987

PKCSwipeReusableView

示例

image image

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install




import PKCSwipeReusableView

class ReusableView: PKCSwipeReusableView{ }

class ViewController: UIViewController{

    override func viewDidLoad(){
        self.collectionView.register(ReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "ReusableView")
        self.collectionView.dataSource = self
    }
    
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        if kind == UICollectionElementKindSectionHeader{
            let reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "ReusableView", for: indexPath) as! ReusableView

            reusableView.label.text = "ReusableView Header"
            let pkcButton1 = PKCButton(frame: .zero)
            pkcButton1.backgroundColor = .red
            pkcButton1.setTitle("Delete", for: .normal)
            reusableView.addRightSwipe(pkcButton1)
            pkcButton1.addTarget({ (button) in
                print(button)
            })
            if indexPath.section < 3{
                let pkcButton2 = PKCButton(frame: .zero)
                pkcButton2.backgroundColor = .green
                pkcButton2.setTitle("Save", for: .normal)
                reusableView.addLeftSwipe(pkcButton2)
            }
            return reusableView
        }else{
            assert(false, "Unexpected element kind")
        }
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize(width: UIScreen.main.bounds.width, height: 50)
    }

}

安装

PKCSwipeReusableView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:

pod "PKCSwipeReusableView"

作者

pikachu987, [email protected]

许可证

PKCSwipeReusableView 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。