github地址,https://github.com/xiongxiong/ActionCell
觉得好的话,就帮忙打个星,谢谢。
ActionCellEasy to use UITableViewCell implementing swiping to trigger actions (known from the Mailbox App)
ContentsFeatures[x] Flexible action support
[x] Support default action
[x] Customized action width
[x] Customized action control
RequirementsiOS 8.0+ / Mac OS X 10.11+ / tvOS 9.0+
Xcode 8.0+
Swift 3.0+
InstallationCocoaPodsCocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapodsTo 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' endThen, run the following command:
$ pod installCarthageCarthage 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 carthageTo integrate ActionCell into your Xcode project using Carthage, specify it in your Cartfile:
github 'xiongxiong/ActionCell' ~> 1.0.0Run carthage update to build the framework and drag the built ActionCell.framework into your Xcode project.
ManuallyIf you prefer not to use either of the aforementioned dependency managers, you can integrate ActionCell into your project manually.
ExampleOpen the example project, build and run.
ProtocolsCellActionProtocolpublic protocol CellActionProtocol { func setForeColor(color: UIColor) func setForeAlpha(alpha: CGFloat) }UsageInherit ActionControl & implement CellActionProtocolpublic 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 ActionCellfunc 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 }PropertiesActionsactionsLeft: [CellAction] // Actions - Left
actionsRight: [CellAction] // Actions - Right
StyleanimationStyle: 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
BehaviorenableDefaultAction: 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
AnimationanimationDuration: 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
Authorxiongxiong, ximengwuheng@163.com
LicenseActionCell is available under the MIT license. See the LICENSE file for more info.