OOButtonNode
custom button class for SpriteKit. It has almost all useful logic from UIButton.
OOButtonNode
is Swift 4 library, works on iOS 8+ and requires ARC to build.
CocoaPods is the recommended way to add OOButtonNode to your project.
- Add a pod entry for OOButtonNode to your Podfile `pod 'OOButtonNode'
- Install the pod(s) by running
pod install
. - Include OOButtonNode wherever you need it with
import OOButtonNode
.
Alternatively you can directly add the OOButtonNode.swift
source file to your project.
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- Open your project in Xcode, then drag and drop
OOButtonNode.swift
onto your project (use the "Product Navigator view").
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.
This code is distributed under the terms and conditions of the MIT license.