Giter Club home page Giter Club logo

otsortbutton's Introduction

OTSortButton

Description

OTSortButton is a UIButton library useful for sorting.

Features

・Change appearance for each parts and sort types.

Demo

otsortbuttondemo

Usage

1.Set OTSortButton to Custom Class and Module of your UIButton.

2017-09-15 21 10 54

The appearance can be set with IBInspectable.

2017-09-15 21 27 45

2.Import and connect IBOutlet

import OTSortButton

@IBOutlet var sortButtonCollection: [OTSortButton]!

3.If you want to set the key on the button, please set it as the sort key

@IBOutlet weak var yourSortButton: OTSortButton!

yourSortButton.sortKey = "yourKey"

4.Connect IBAction

@IBAction func tappedSortButton(_ sender: OTSortButton) {
	for sortButton in sortButtonCollection {
		if sortButton == sender {
	        	let key = sortButton.sortKey
			switch sortButton.sortType {
			case .none:
			
		    		sortButton.sortType = .ascend
		    		// Sort ascend here.
       	    			//e.g. sortedArray = yourArray.sorted(by: { $0[key]! < $1[key]! })
				
    			case .ascend:
			
       				sortButton.sortType = .descend
				// Sort descend here.
     	   			//e.g. sortedArray = yourArray.sorted(by: { $0[key]! > $1[key]! })
				
        		case .descend:
			
				sortButton.sortType = .none
           			// Undo here.
           			//e.g. sortedArray = yourArray     
			}
   		} else {
       			sortButton.sortType = .none
     		}
	}
	yourView.reloadData()
}

Install

CocoaPods

Add this to your Podfile.

pod 'OTSortButton'

Carthage

Add this to your Cartfile.

github "PKPK-Carnage/OTSortButton"

Help

If you want to support this framework, you can do these things.

  • Please let us know if you have any requests for me.

    I will do my best to live up to your expectations.

  • You can make contribute code, issues and pull requests.

    I promise to confirm them.

Licence

MIT

Author

PKPK-Carnage🦎

otsortbutton's People

Contributors

frog-frog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.