SwiftShareBubbles 1.2.0

SwiftShareBubbles 1.2.0

测试已测试
语言语言 SwiftSwift
许可证 NOASSERTION
发布最后发布2019年3月
SPM支持 SPM

Takeshi Fujiki 维护。



SwiftShareBubbles

Version License Platform Carthage compatible Bitrise codebeat badge

Swift 编写的 iOS 动画社交分享按钮控件。此库受到了 AAShareBubbles 的启发。

ShareBubbles1

我尝试了 AAShareBubbles 的 Swift 版本,它大部分都可以正常工作。但是,我不能在协议扩展中使用 AAShareBubbles(Objective-c 代码)。因此,我完全使用 Swift 创建了 SwiftShareBubbles。

要求

iOS 8.0 或更高,使用 Swift 编写。

安装

CocoaPods

pod 'SwiftShareBubbles'

Carthage

SwiftRoutes 兼容 Carthage。将其添加到您的 Cartfile

github "takecian/SwiftShareBubbles"

使用方法

  1. 实例化 SwiftShareBubbles,指定圆心位置和半径。
  2. 选择要显示的社交按钮。
  3. 设置代理
  4. 调用显示方法。
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

支持的按钮

  • Facebook
  • Twitter
  • LINE
  • Google Plus
  • YouTube
  • Instagram
  • Pinterest
  • WhatsApp
  • Linkedin
  • 微博
  • Safari

自定义图标

您可以根据以下方法添加自定义图标,

class ViewController: UIViewController, SwiftShareBubblesDelegate {

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

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

许可证

MIT