8000 GitHub - langelee/UIClosures: Swift closure library for UIKit
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Swift closure library for UIKit

License

Notifications You must be signed in to change notification settings

langelee/UIClosures

 
 

Repository files navigation

UIClosures [![CocoaPod][pd-bdg]][pd] Carthage compatibleMIT licenseIssues

by ark. tweet @arkverse for any feature requests. Feedback is greatly appreciated! [pd-bdg]: https://img.shields.io/cocoapods/v/UIClosures.svg [pd]: http://cocoadocs.org/docsets/UIClosures

About

A Swift closure library for UIKit that makes events significantly easier and cleaner. Currently supports closures on UIControl events and UIGestureRecognizers (all subclasses). We will be adding more closure support as we go along. Memory managed and written completely in Swift.

All the UIControlEvents are supported, and multiple closures can be added to the same event.

Quick example:

button.on(.TouchUpInside, (sender: AnyObject) -> () {
	let button = sender as! UIButton
	button.setTitle("Pressed", forControlState:.Normal)
})

Be sure to check out our SwiftRecord library too!

Visit ark for a more beginner friendly guide to UIClosures

If you love UIClosures, tweet it! tweet button

Installation

  1. Edit your Podfile to use frameworks and add UIClosures:

     platform :ios, '8.0'
     use_frameworks!
    
     pod 'UIClosures', '~> 0.0.2'
    
  2. run pod install

via Carthage

  1. Just add UIClosures to your Cartfile:

    github "arkverse/UIClosures" >= 0.0.1

  2. and run carthage update

Manual Installation

Drag and drop either Classes/UIClosures.swift or UIClosures.framework into your project

Usage

UIControls

  1. import UIClosures into your file (if needed)

  2. call on on your UIControl or one of the convenience methods like onTouchUpInside

    // Make sure you set your capture list to break your class-closure strong reference loop
    on(.TouchUpInside, listener: { [unowned self] (sender) -> () in
    	self.title = "New ViewController Title!"
    	let button = sender as! UIButton
    	button.titleLabel?.font = UIFont.systemFont
    })
    // Can add another closure to the same event, convenience method used here
    button.onTouchUpInside() {[weak button = button] (sender) -> () in
    	button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
    })
  3. Note that you most likely need your capture list for each closure

UIGestureRecognizer

Use any of the subclasses you want. You must use the closure initializer and not the target: action: initializer:

let tap = UITapGestureRecognizer() { (gesture: UITapGestureRecognizer) -> () in
	println("got a tap")
}

tap.onGesture() { (gesture: UITapGestureRecognizer) -> () in
	println("got this tap again")
}

Will call all of your closures

Again, remember your capture list if referring to any variables

##Roadmap

  • add more closures
  • testing

License

UIClosures is available under the MIT license. See the LICENSE file for more information.

Check out ark for more about us and check out our other Swift libraries

ga tracker

About

Swift closure library for UIKit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.0%
  • Ruby 2.4%
  • C++ 1.6%
0