Latest 0.0.2
License MIT
Platforms ios 8.0

SgButton in Swift for SpriteKit


When starting working with SpriteKit, we have found that that framework has not supported buttons yet. Some current open-source is not good enough for me. Thus I have created this component to fill my needs. The code is written in Swift. We share it in hope it may be usefull to others as well as having more contributes / improvements from other programmers.


Simple selector


  • Create buttons from image files or texture (sprite sheet)
  • Create rectangle / round corner rectangle buttons
  • Create buttons with string (text)
  • Work well with defferent screen (rentina)
  • Work well after being rotated, changed anchorPoint


Add files directly

Copy the file SgButton.swift (in the SgButton folder) into your project.


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

$ gem install cocoapods

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

source ''
platform :ios, '9.0'

pod 'sgbutton'

Then, run the following command:

$ pod install


Use image files to create buttons:

    var btn1 = SgButton(normalImageNamed: "back.png")
    var btn2 = SgButton(normalImageNamed: "back.png", highlightedImageNamed: "back_d.png", disabledImageNamed: "back_x.png", buttonFunc: tappedButton)

Use textures (from spritesheet) to create buttons:

    var btn3 = SgButton(normalTexture:, highlightedTexture: buttonSheet.buy_d(), buttonFunc: tappedButton)

Create text buttons (round corner button):

    var btn4 = SgButton(normalString: "Tap me", normalStringColor: UIColor.blueColor(), size: CGSizeMake(200, 40), cornerRadius: 10.0, buttonFunc: tappedButton)

Create text buttons with image as background

    var btn5 = SgButton(normalTexture: buttonSheet.greenbutton(), highlightedTexture: buttonSheet.yellowbutton(), buttonFunc: tappedButton)
    btn5.setString(.Normal, string: "Are you sure?", fontSize: 24, stringColor: UIColor.whiteColor())


Apache License 2.0

Latest podspec

    "name": "sgbutton",
    "version": "0.0.2",
    "summary": "Button library for SpriteKit in Swift",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "nguyenpham": "[email protected]"
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "0.0.2"
    "source_files": "SgButton/*.swift"

Pin It on Pinterest

Share This