Code Monkey home page Code Monkey logo

amazingbubbles's Introduction

AmazingBubbles

Bubble pickers, inspired by Apple

Requirements:

  • iOS 9.1+
  • XCode 8.0+
  • Swift 3.0

Installation

AmazingBubbles Library is available through CocoPods. To install, add the following line to your Podfile:

pod 'AmazingBubbles', '~> 0.0'

Usage:

  1. Import library as follows:
import AmazingBubbles
  1. Add ContentBubblesView to your VC;
  2. Add delegate and dataSource for ContentBubblesView instance:
class ViewController: UIViewController {

  @IBOutlet weak var bubblesView: ContentBubblesView! {
      didSet {
          bubblesView.delegate = self
          bubblesView.dataSource = self
      }
  }
  
}
  1. Implement protocols :
public protocol ContentBubblesViewDelegate: class {
    func minimalSizeForBubble(in view: ContentBubblesView) -> CGSize
    func maximumSizeForBubble(in view: ContentBubblesView) -> CGSize
    
    func contentBubblesView(_ view: ContentBubblesView, didSelectItemAt index: Int)
    func contentBubblesView(_ view: ContentBubblesView, shouldChangeSizeForItemAt index: Int) -> Bool
    func contentBubblesView(_ view: ContentBubblesView, didChangeSizeForItemAt index: Int)
}

public protocol ContentBubblesViewDataSource: class {
    func countOfSizes(in view: ContentBubblesView) -> Int
    
    func numberOfItems(in view: ContentBubblesView) -> Int
    func addOrUpdateBubbleView(forItemAt index: Int, currentView: BubbleView?) -> BubbleView
}

for example:

extension ViewController: ContentBubblesViewDataSource {
    func countOfSizes(in view: ContentBubblesView) -> Int {
        return 3
    }
    
    func numberOfItems(in view: ContentBubblesView) -> Int {
        return 15
    }
    
    func addOrUpdateBubbleView(forItemAt index: Int, currentView: BubbleView?) -> BubbleView {
        var view: BubbleView = currentView ?? BubbleView()        
        view.backgroundColor = .clear
        let randomOrigin = CGPoint(x: CGFloat(drand48() * Double(self.view.frame.width * 2 / 3)),
                                   y: CGFloat(drand48() * Double(self.view.frame.height * 2 / 3)))
        view.frame = CGRect(origin: randomOrigin,
                            size: .zero)
        return view
    }
}
  1. And than call:
bubblesView.reload(randomizePosition: true) 

Additional features:

  • You can create custom views by subclassing BubbleView
  • You can enable/disable gestures in ContentBubblesView:
bubblesView.tapEnabled = true
bubblesView.panEnabled = false
  • Also you can change some settings in BubbleConstants struct or play with some settings of UIDynamicBehaviors.

amazingbubbles's People

Contributors

ollie-eman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.