Swift Ruby Objective-C
Latest commit 546f37a Jul 25, 2017 @efremidze 1.0.7
Permalink
Failed to load latest commit information.
Example 1.0.6 May 14, 2017
Images Updated Demo Apr 13, 2017
Magnetic.xcodeproj 1.0.7 Jul 25, 2017
Sources 1.0.7 Jul 25, 2017
.gitignore Initial commit Mar 9, 2017
CHANGELOG.md 1.0.7 Jul 25, 2017
LICENSE Initial commit Mar 9, 2017
Magnetic.podspec 1.0.7 Jul 25, 2017
Package.swift created project Mar 9, 2017
README.md Update README.md May 25, 2017

README.md

Magnetic

Language Version License Platform Carthage compatible

Magnetic is a customizable bubble picker like the Apple Music genre selection.

$ pod try Magnetic

Features

  • Adding/Removing Nodes
  • Selection/Deselection/Removed Animations
  • Multiple Selection
  • Images
  • Multiline Label

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

Usage

A Magnetic object is an SKScene.

To display, you present it from an SKView object.

import Magnetic

class ViewController: UIViewController {

    var skView: SKView {
        return view as! SKView
    }

    override func loadView() {
        super.loadView()

        self.view = SKView(frame: self.view.bounds)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let magnetic = Magnetic(size: self.view.bounds.size)
        skView.presentScene(magnetic)
    }

}

Properties

var magneticDelegate: MagneticDelegate? // magnetic delegate
var allowsMultipleSelection: Bool // controls whether you can select multiple nodes. defaults to true
var selectedChildren: [Node] // returns selected chidren

Nodes

A Node object is a circular SKShapeNode subclass.

Interaction

// add node
func addNode() {
    let node = Node(text: "Italy", image: UIImage(named: "italy"), color: .red, radius: 30)
    magnetic.addChild(node)
}

// remove node
func removeNode() {
    node.removeFromParent()
}

Properties

var text: String? // node text
var image: UIImage? // node image
var color: UIColor // node color. defaults to white

Animations

override func selectedAnimation() {
    // override selected animation
}

override func deselectedAnimation() {
    // override deselected animation
}

override func removeAnimation(completion: @escaping () -> Void) {
    // override remove animation
}

Delegation

The MagneticDelegate protocol provides a number of functions for observing the current state of nodes.

func magnetic(_ magnetic: Magnetic, didSelect node: Node) {
    // handle node selection
}

func magnetic(_ magnetic: Magnetic, didDeselect node: Node) {
    // handle node deselection
}

Customization

Subclass the Node for customization.

For example, a node with an image by default:

class ImageNode: Node {
    override var image: UIImage? {
        didSet {
            sprite.texture = image.map { SKTexture(image: $0) }
        }
    }
    override func selectedAnimation() {}
    override func deselectedAnimation() {}
}

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "Magnetic"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/Magnetic"

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Credits

https://github.com/igalata/Bubble-Picker

License

Magnetic is available under the MIT license. See the LICENSE file for more info.