Magnetic is a customizable bubble picker like the Apple Music genre selection.
$ pod try Magnetic
- Adding/Removing Nodes
- Selection/Deselection/Removed Animations
- Multiple Selection
- Images
- Multiline Label
- Documentation
- iOS 13.0+ (Magnetic 3.3.x), iOS 9.0+ (Magnetic 3.2.1)
- Swift 5 (Magnetic 3.x), Swift 4 (Magnetic 2.x), Swift 3 (Magnetic 1.x)
A Magnetic object is an SKScene.
To display, you present it from an SKView object.
import Magnetic
classViewController:UIViewController{varmagnetic:Magnetic?overridefunc loadView(){
super.loadView()letmagneticView=MagneticView(frame:self.view.bounds)
magnetic = magneticView.magnetic
self.view.addSubview(magneticView)}}varmagneticDelegate:MagneticDelegate? // magnetic delegate
varallowsMultipleSelection:Bool // controls whether you can select multiple nodes. defaults to true
varselectedChildren:[Node] // returns selected chidrenA Node object is a SKShapeNode subclass.
// add circular node
letnode=Node(text:"Italy", image:UIImage(named:"italy"), color:.red, radius:30)
magnetic.addChild(node)
// add custom node
letnode=Node(text:"France", image:UIImage(named:"france"), color:.blue, path: path, marginScale:1.1)
magnetic.addChild(node)
// remove node
node.removeFromParent()vartext:String? // node text
varimage:UIImage? // node image
varcolor:UIColor // node coloroverridefunc selectedAnimation(){
// override selected animation
}overridefunc deselectedAnimation(){
// override deselected animation
}overridefunc removedAnimation(completion:@escaping()->Void){
// override removed animation
}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
}Subclass the Node for customization.
For example, a node with an image by default:
classImageNode:Node{overridevarimage:UIImage?{
didSet {
texture = image.map{SKTexture(image: $0)}}}overridefunc selectedAnimation(){}overridefunc deselectedAnimation(){}}To install with CocoaPods, simply add this in your Podfile:
use_frameworks!pod"Magnetic"To install with Carthage, simply add this in your Cartfile:
github"efremidze/Magnetic"- 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.
https://github.com/igalata/Bubble-Picker
Magnetic is available under the MIT license. See the LICENSE file for more info.
