Coder Social home page Coder Social logo

qigeligedongdongqiang / swiftsharebubbles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from takecian/swiftsharebubbles

1.0 2.0 0.0 420 KB

Animated Social share buttons control for iOS written in Swift

License: Other

Ruby 5.66% Swift 90.80% Objective-C 3.54%

swiftsharebubbles's Introduction

SwiftShareBubbles

Version License Platform Carthage compatible

Animated Social share buttons control for iOS written in Swift. This library is inspired AAShareBubbles.

ShareBubbles1

I tried AAShareBubbles with Swift, it mostly worked. But I cannot use AAShareBubbles(Objective-c code) in protocol extension. So I created SwiftShareBubbles in pure Swift.

Requirements

iOS 8.0 or later, written in Swift3.

Installation

Cocoapods

pod 'SwiftShareBubbles'

Carthage

SwiftRoutes is compatible with Carthage. Add it to your Cartfile:

github "takecian/SwiftShareBubbles"

Usage

  1. Instantiate SwiftShareBubbles, specify center position and radius of Circle.
  2. Choose social buttons to be shown.
  3. Set delegate
  4. Call show method.
class ViewController: UIViewController, SwiftShareBubblesDelegate {

    var bubbles: SwiftShareBubbles?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        bubbles = SwiftShareBubbles(point: CGPoint(x: view.frame.width / 2, y: view.frame.height / 2), radius: 100, in: view)
        bubbles?.showBubbleTypes = [Bubble.twitter, Bubble.line, Bubble.safari]
        bubbles?.delegate = self
    }

    // SwiftShareBubblesDelegate
    func bubblesTapped(bubbles: SwiftShareBubbles, bubbleId: Int) {
        if let bubble = Bubble(rawValue: bubbleId) {
            print("\(bubble)")
            switch bubble {
            case .facebook:
                break
            case .twitter:
                if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
                    guard let composer = SLComposeViewController(forServiceType: SLServiceTypeTwitter) else { return }
                    composer.setInitialText("test test")
                    present(composer, animated: true, completion: nil)
                }
                break
            case .line:
                break
            default:
                break
            }
        } else {
            // custom case
        }
    }

    func bubblesDidHide(bubbles: SwiftShareBubbles) {
    }

    @IBAction func buttonTapped(_ sender: Any) {
        bubbles?.show()
    }
}

ShareBubbles2

Supported buttons

  • facebook
  • Twitter
  • LINE
  • google plus
  • Youtube
  • Instagram
  • Pintereset
  • Whatsapp
  • Linkedin
  • Weibo
  • Safari

Custom icons

You can add custom icons as follows,

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
	    let customBubbleId = 100
	    let customAttribute = ShareAttirbute(bubbleId: customBubbleId, icon: UIImage(named: "Custom")!, backgroundColor: UIColor.white)
	    bubbles?.customBubbleAttributes = [customAttribute]
    }

     func bubblesTapped(bubbles: SwiftShareBubbles, bubbleId: Int) {
        if customBubbleId == bubbleId {
            // custom case
            print("custom tapped")
        }
    }

License

MIT

swiftsharebubbles's People

Contributors

takecian avatar basthomas avatar

Stargazers

Jadon.Mao avatar

Watchers

James Cloos avatar Jadon.Mao 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.