GithubHelp home page GithubHelp logo

swiftdropdown's Introduction

SwiftDropdown

Simple customizable Dropdown component written in Swift.

Usage

// 1. Create dropdown
let dropdown = DropdownView(options: [
  DropdownView.Option(title: "Edit",   icon: UIImage(named: "edit")!,   action: { print("selected edit")   }),
  DropdownView.Option(title: "Share",  icon: UIImage(named: "share")!,  action: { print("selected share")  }),
  DropdownView.Option(title: "Delete", icon: UIImage(named: "delete")!, action: { print("selected delete") })
], target: self)

// 2. Attach dropdown to your button
dropdown.attachTo(myButton, openDirection: .leftDown)

preview

Gestures

  • Tap the buton: opens the dropdown
  • Long press the button: opens the dropdown and allows you to slide your finger over the option you want. Option is selected when you lift your finger.
  • Drag the button: When you get used to the long press gesture, you tend to start moving your finger before there was enough time to trigger the long press. So if you tap and start moving your finger it will open the dropdown as well.

Options

struct Option {
  let title: String?
  let icon: UIImage?
  let action: () -> ()
}

Open Directions

Open direction will anchor the dropdown to the button appropriately and define the open animation direction. You define the Open Direction on the attachTo function. If no direction is passed, defaults to .leftDown.

enum OpenDirection {
  case centerDown, rightDown, leftDown
  case centerUp, rightUp, leftUp
  case rightCenter, leftCenter
  case center
  case screenCenter, screenBottom
}

Appearance

You can customize the dropdown's appearance.

let options = [...]
let dropdown = DropdownView(options: options, target: self)

// Dropdown appearance
dropdown.tintColor = .white
dropdown.backgroundColor = .blue
dropdown.layer.cornerRadius = 8

// Background color on a highlighted/tapped option
dropdown.optionHighlightColor = UIColor(white: 0, alpha: 0.2)

// Color of background overlay
dropdown.backgroundOverlayColor = UIColor(white: 0, alpha: 0.1)

// Spring animation damping
dropdown.springDamping = 0.7

Custom button

swiftdropdown's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ilesh

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.