Latest 0.0.5
Homepage https://github.com/Hassan-Aftab/HASuggestionField
License GNU General Public License
Platforms ios 8.0
Authors ,

HASuggestionField is a iOS suggestion list written in Swift. It suggests list of items provided against any symbol. It allows user to select any of the suggested item from dropdown. Then it applies provided attributes on selected item.
Items are also defined by structs. These structs will define each item’s properties.
Alt text

Simply include HASuggestionField.swift in your project or if you prefer cocoapods

    pod 'HASuggestionField', '0.0.5'

Usage

Create a HASuggestionField in IB or in code (using UIView’s init methods). Then add values for suggestion field, for example:

    @IBOutlet weak var suggestionField: HASuggestionField!

    func setupSuggestionFieldData() {
        let usersValue = HASuggestionFieldValue
            .init(symbol: HASymbol("@"),
                  attributesWhenSelected: [NSAttributedString.Key.foregroundColor: UIColor.blue], 
                  items: getSomeUsers(), 
                  isUnique: false, 
                  setAny: false)

        let tagsValue = HASuggestionFieldValue
            .init(symbol: HASymbol("#"), 
                  attributesWhenSelected: [NSAttributedString.Key.backgroundColor : UIColor.lightGray], 
                  items: getSomeHastags(), 
                  isUnique: false, 
                  setAny: true)

        suggestionField.setupWithValues([tagsValue, usersValue])
    }

    func getSomeUsers() -> [HASuggestionFieldItem] {

        let user1 = HASuggestionFieldItem.init(title: "Hassan", detail: "[email protected]", image: nil, imgURL: nil, replaceDetail: false)

        let user2 = HASuggestionFieldItem.init(title: "John", detail: "[email protected]", image: nil, imgURL: nil, replaceDetail: false)

        let user3 = HASuggestionFieldItem.init(title: "Jack", detail: "[email protected]", image: nil, imgURL: nil, replaceDetail: false)

        let user4 = HASuggestionFieldItem.init(title: "Tyrion", detail: "[email protected]", image: nil, imgURL: nil, replaceDetail: false)

        return [user1, user2, user3, user4]
    }

    func getSomeHastags() -> [HASuggestionFieldItem] {
        let tag1 = HASuggestionFieldItem.init(title: "developer", detail: "", image: nil, imgURL: nil, replaceDetail: false)

        let tag2 = HASuggestionFieldItem.init(title: "coder", detail: "", image: nil, imgURL: nil, replaceDetail: false)

        let tag3 = HASuggestionFieldItem.init(title: "swift", detail: "", image: nil, imgURL: nil, replaceDetail: false)

        let tag4 = HASuggestionFieldItem.init(title: "ios", detail: "", image: nil, imgURL: nil, replaceDetail: false)

        return [tag1, tag2, tag3, tag4]
    }

You can also implement HASuggestionFieldDelegate to get notified when user enters a symbol or some text against a symbol:

    func haSuggestionField(_ field: HASuggestionField, didChangeTextfor symbol: String, word: String) {
        print("User entered (word) for symbol (symbol)")
    }

    func haSuggestionField(_ field: HASuggestionField, didEnter symbol: String) {
        print("User entered the symbol (symbol)")
    }

Values can be added or removed

All properties can be manually modified.

License and Authorship

Released under the GNU GENERAL PUBLIC LICENSE. Copyright Hassan Aftab. Please open issues on GitHub.

Latest podspec

{
    "name": "HASuggestionField",
    "swift_version": "4.0",
    "version": "0.0.5",
    "summary": "HASuggestionField is a iOS suggestion list written in Swift. It suggests list of items provided against any symbol. It allows user to select any of the suggested item from dropdown. Then it applies provided attributes on selected item. Items are also defined by structs. These structs will define each item's properties.",
    "platforms": {
        "ios": "8.0"
    },
    "xcconfig": {
        "OTHER_LDFLAGS": "-lz"
    },
    "homepage": "https://github.com/Hassan-Aftab/HASuggestionField",
    "license": "GNU General Public License",
    "authors": {
        "Hassan Aftab": "[email protected]",
        "tag": "0.0.5"
    },
    "source": {
        "git": "https://github.com/Hassan-Aftab/HASuggestionField.git",
        "tag": "master"
    },
    "source_files": [
        "Classes",
        "HASuggestionField/HASuggestionField.swift"
    ]
}

Pin It on Pinterest

Share This