Giter Site home page Giter Site logo

mohsinalimat / actioncell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xiongxiong/actioncell

1.0 2.0 0.0 7.74 MB

Easy to use UITableViewCell implementing swiping to trigger actions (known from the Mailbox App)

License: MIT License

Swift 96.82% Ruby 2.42% Objective-C 0.76%

actioncell's Introduction

ActionCell

CI Status Version Platform Swift 3.0 Carthage compatible License

Easy to use UITableViewCell implementing swiping to trigger actions (known from the Mailbox App)

ActionCell

Contents

Features

  • Flexible action support
  • Support default action
  • Customized action width
  • Customized action control

Requirements

  • iOS 8.0+ / Mac OS X 10.11+ / tvOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate ActionCell into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ActionCell', '~> 1.0.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate ActionCell into your Xcode project using Carthage, specify it in your Cartfile:

github "xiongxiong/ActionCell" ~> 1.0.0

Run carthage update to build the framework and drag the built ActionCell.framework into your Xcode project.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ActionCell into your project manually.

Example

Open the example project, build and run.

Protocols

CellActionProtocol

public protocol CellActionProtocol {
    func setForeColor(color: UIColor)
    func setForeAlpha(alpha: CGFloat)
}

Usage

Inherit ActionControl & implement CellActionProtocol

public class ActionControl: UIControl {}
public class TextAction: ActionControl, CellActionProtocol {
    var label: UILabel = UILabel()
    ...

    public func setForeColor(color: UIColor) {
        label.tintColor = color
    }

    public func setForeAlpha(alpha: CGFloat) {
        label.alpha = alpha
    }
  }

IconAction & TextAction are already implemented, you can use it straightforwardly without implementing CellActionProtocol, or you can choose to implement CellActionProtocol to use your own ActionControl.

Initialize ActionCell

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch (indexPath as NSIndexPath).row {
        case 0:
            let cell = ActionCell<IconAction>() // create ActionCell
            cell.textLabel?.text = "Colorful actions"
            cell.defaultActionIndexLeft = 1 // set default action index to be triggered, default is the first one.
            cell.actionsLeft = [
                IconAction(iconImage: UIImage(named: "0")!, backColor: UIColor(red:0.95, green:0.33, blue:0.58, alpha:1.00)) {
                    self.output.text = ("cell 0 -- left 0 clicked")
                },
                IconAction(iconImage: UIImage(named: "1")!, backColor: UIColor(red:1.00, green:0.78, blue:0.80, alpha:1.00), width: 140) {
                    self.output.text = ("cell 0 -- left 1 clicked")
                },
                IconAction(iconImage: UIImage(named: "2")!, backColor: UIColor(red:0.51, green:0.83, blue:0.73, alpha:1.00)) {
                    self.output.text = ("cell 0 -- left 2 clicked")
                },
            ] // set actions of the action cell
            cell.defaultActionIndexRight = 2 // set default action index to be triggered, default is the first one.
            cell.actionsRight = [
                IconAction(iconImage: UIImage(named: "0")!, backColor: UIColor(red:0.14, green:0.69, blue:0.67, alpha:1.00)) {
                    self.output.text = ("cell 0 -- left 0 clicked")
                },
                IconAction(iconImage: UIImage(named: "1")!, backColor: UIColor(red:0.51, green:0.83, blue:0.73, alpha:1.00)) {
                    self.output.text = ("cell 0 -- left 1 clicked")
                },
                IconAction(iconImage: UIImage(named: "2")!, backColor: UIColor(red:1.00, green:0.78, blue:0.80, alpha:1.00), width: 140) {
                    self.output.text = ("cell 0 -- left 2 clicked")
                },
            ] // set actions of the action cell
            return cell
        default:
          break
        }

Properties

Actions

  • actionsLeft: [CellAction] // Actions - Left
  • actionsRight: [CellAction] // Actions - Right

Style

  • animationStyle: AnimationStyle = none | ladder | ladder_emergence | concurrent // Action animation style
  • defaultActionTriggerPropotion: CGFloat // The propotion of (state public to state trigger-prepare / state public to state trigger), about where the default action is triggered
  • defaultActionIconColor: UIColor? // Default action's icon color
  • defaultActionBackImage: UIImage? // Default action's back image
  • defaultActionBackColor: UIColor? // Default action's back color

Behavior

  • enableDefaultAction: Bool // Enable default action to be triggered when the content is panned to far enough
  • defaultActionIndexLeft: Int // Index of default action - Left
  • defaultActionIndexRight: Int // Index of default action - Right

Animation

  • animationDuration: NSTimeInterval // Spring animation - duration of the animation
  • animationDelay: TimeInterval // Spring animation - delay of the animation
  • springDamping: CGFloat // Spring animation - spring damping of the animation
  • initialSpringVelocity: CGFloat // Spring animation - initial spring velocity of the animation
  • animationOptions: UIViewAnimationOptions // Spring animation - options of the animation

Author

xiongxiong, [email protected]

License

ActionCell is available under the MIT license. See the LICENSE file for more info.

actioncell's People

Stargazers

MohsinAli avatar

Watchers

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