Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

wromijn/OOButtonNode

Open more actions menu
 
 

Repository files navigation

OOButtonNode

platform ios Swift 4.0 CocoaPods compatible License: MIT Twitter URL

OOButtonNode custom button class for SpriteKit. It has almost all useful logic from UIButton.

Alt Text

Requirements

OOButtonNode is Swift 4 library, works on iOS 8+ and requires ARC to build.

Adding OOButtonNode to your project

CocoaPods

CocoaPods is the recommended way to add OOButtonNode to your project.

  1. Add a pod entry for OOButtonNode to your Podfile `pod 'OOButtonNode'
  2. Install the pod(s) by running pod install.
  3. Include OOButtonNode wherever you need it with import OOButtonNode.

Source files

Alternatively you can directly add the OOButtonNode.swift source file to your project.

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Open your project in Xcode, then drag and drop OOButtonNode.swift onto your project (use the "Product Navigator view").

Usage

You can create OOButtonNode programmatically or via *.sks file, for callback we use pressedBlock:

let firstButton = childNode(withName: "firstButton") as! OOButtonNode
firstButton.pressedBlock = { (buttonNode) in
    NSLog("firstButton pressed")
}

let fourthButton = OOButtonNode()
addChild(fourthButton)

You can set text and text color onto the button:

firstButton.setTitle("Hello", for: .normal)
firstButton.setTitleColor(.black, for: .normal)

Or You can use images or background colors for button states:

firstButton.setImage(UIImage(named: "hello")!, for: .normal)
firstButton.setImage(UIImage(named: "hello_pressed")!, for: .pressed)

fourthButton.setBackgroundColor(.yellow, for: .normal)
fourthButton.setBackgroundColor(.red, for: .pressed)
fourthButton.setBackgroundColor(.lightGray, for: .disabled)

Moreover You can add scale effect to the pressed state:

firstButton.pressedScale = 0.9

Additionally You can change font and button size(specially for background color using)

All this logic is in example project.

License

This code is distributed under the terms and conditions of the MIT license.

About

Button for SpriteKit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 90.1%
  • Ruby 5.3%
  • Objective-C 4.6%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.