Giter Club home page Giter Club logo

pkhgridview's Introduction

PkhGridView

๐Ÿ‘ป Easy CollectionViewCell Controller

๋ชฉํ‘œ

cell์„ ๊ฐ€๋กœ๋กœ ์ˆซ์ž ์ง€์ •ํ•˜์—ฌ ๋ฐฐ์—ดํ•˜๊ณ  ์‹ถ์„๋•Œ

columnCount ์ˆซ์ž์— ๋”ฐ๋ผ ๊ฐ€๋กœ ๊ฐฏ์ˆ˜๊ฐ€ ์ •ํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ฆฌ๋“œ๋ทฐ width ๊ธฐ๋ฐ˜์œผ๋กœ cell์˜ width๊ฐ€ ์ž๋™์œผ๋กœ ๋Š˜์–ด๋‚จ (๊ฐ€๋กœ์— ๋Œ€ํ•œ ๋†’์ด ๊ฐ€๋ณ€ ์ฒ˜๋ฆฌ๋Š” getGridViewHeight ์ด์šฉํ•˜์—ฌ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅํ•จ)

columnCount == 0 ์œผ๋กœ ์…‹ํŒ…์‹œ Cell์˜ Xib์˜ Width ํฌ๊ธฐ๋กœ๋Œ€๋กœ Cell์˜ ๊ฐ€๋กœ ์ˆซ์ž๊ฐ€ ๊ฐ€๋ณ€์œผ๋กœ ์ง€์ •๋˜์–ด ๊ทธ๋ ค์ง ๊ทธ๋ฆฌ๋“œ๋ทฐ ๊ฐ€๋กœ ์‚ฌ์ด์ฆˆ๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ํ•˜๋‹จ์œผ๋กœ ๋‚ด๋ ค๊ฐ๊ฐ

GirdView Xib์—์„œ Cell์˜ ์ด๋ฆ„์ด๋‚˜ ์—ฌ๋ ค๊ฐ€์ง€ ์…‹ํŒ…์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ์ฝ”๋“œ๊ฐ€ ๊ฑฐ์˜ ์—†์Œ


SampleTestApp SampleTestApp


Test Code


let texts = ["ํ…Œ์ŠคํŠธ1","ํ…Œ์ŠคํŠธ2","ํ…Œ์ŠคํŠธ3","ํ…Œ์ŠคํŠธ4","ํ…Œ์ŠคํŠธ5","ํ…Œ์ŠคํŠธ6","ํ…Œ์ŠคํŠธ7","ํ…Œ์ŠคํŠธ8","ํ…Œ์ŠคํŠธ9"]
let data = GridViewData(itemList: texts)
gridView.configure(data: data) { (name, object) in
    print(name)
}

Core Functions

protocol PkhGridViewCellProtocol: UICollectionViewCell {
    var actionClosure: OnActionClosure? { get set }
    
    static func getGridViewHeight(data: Any?, width: CGFloat) -> CGFloat
    func configure(_ data: Any?)
}


@IBInspectable var cellName: String {
    get {
        return cellType.className
    }
    set {
        cellType = (swiftClassFromString(newValue).self as! PkhGridViewCellProtocol.Type)
    }
}
@IBInspectable var columnCount: Int = 0 {
    didSet {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.columnCount = columnCount
        }
    }
}
@IBInspectable var columnSpacing: CGFloat {
    get {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            return layout.minimumColumnSpacing
        }
        return 0
    }
    set {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.minimumColumnSpacing = newValue
        }
    }
}
@IBInspectable var lineSpacing: CGFloat {
    get {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            return layout.minimumInteritemSpacing
        }
        return 0
    }
    set {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.minimumInteritemSpacing = newValue
        }
    }
}
@IBInspectable var showLineCount: Int = 1 {
    didSet {
        guard let data = self.data, data.itemList.count > 0 else { return }
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.invalidateLayout()
            self.frame.size.height = self.showLineHeight
        }
    }
}

@IBInspectable var heightFit: Bool = true

@IBInspectable var isShowBottomLine: Bool {
    get {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            return layout.isShowBottomLine
        }
        return false
    }
    set {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.isShowBottomLine = newValue
        }
    }
}

@IBInspectable var bottomLineColor: UIColor {
    get {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            return layout.bottomLineColor
        }
        return UIColor.gray
    }
    set {
        if let layout = self.collectionView.collectionViewLayout as? GridViewFlowLayout {
            layout.bottomLineColor = newValue
        }
    }
}


@IBInspectable public var topInset: CGFloat {
    get { return sectionInset.top }
    set { sectionInset.top = newValue }
}

@IBInspectable public var bottomInset: CGFloat {
    get { return sectionInset.bottom }
    set { sectionInset.bottom = newValue }
}

@IBInspectable public var leftInset: CGFloat {
    get { return sectionInset.left }
    set { sectionInset.left = newValue }
}

@IBInspectable public var rightInset: CGFloat {
    get { return sectionInset.right }
    set { sectionInset.right = newValue }
}

pkhgridview's People

Contributors

pkh0225 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.