WWFloatingActionButton

Swift-5.6 iOS-14.0 tag Swift Package Manager-SUCCESS LICENSE

Introduction - 简介

Installation with Swift Package Manager

dependencies: [
    .package(url: "https://github.com/William-Weng/WWFloatingActionButton.git", .upToNextMajor(from: “1.2.5”))
]

WWFloatingActionButtonDelegate

函式 - 函数 功能
currentViewType(with:) 取得該ViewController要彈出的底View - 获取该ViewController要弹出的底View
mainButtonStatus(isTouched:with:) 主按鈕的開關狀態 - 主按钮的开关状态
itemButton(with:didTouched:) 哪一個按鈕被按到,從0開始 - 哪一个按钮被按到,从0开始
itemButtonImages(with:) 子按鈕的圖片 - 子按钮的图片
itemButtonTexts(with:) 子按鈕的文字 - 子按钮的文字
itemButtonTextsFont(with:) 子按鈕的文字字型 - 子按钮的文字字体
itemButtonTextsColor(with:) 子按鈕的文字顏色 - 子按钮的文字颜色
itemButtonAnimationType(with:) 動畫的型式 - 动画的形式

Example

import UIKit
import WWFloatingActionButton

final class ViewController: UIViewController {
    
    enum FloatingActionButtonTag: Int {
        case left = 100
        case right = 101
    }
    
    @IBOutlet weak var leftFloatingActionButton: WWFloatingActionButton!
    @IBOutlet weak var rightFloatingActionButton: WWFloatingActionButton!
    @IBOutlet weak var myImageView: UIImageView!
    @IBOutlet weak var statusImageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "WWFloatingActionButton"
        
        leftFloatingActionButton.myDelegate = self
        rightFloatingActionButton.myDelegate = self
        leftFloatingActionButton.backgroundColor = .clear
        rightFloatingActionButton.backgroundColor = .clear
    }
}

// MARK: - WWFloatButtonDelegate
extension ViewController: WWFloatingActionButtonDelegate {
    
    func currentViewType(with tag: Int) -> WWFloatingActionButton.AnimationViewType {
        return .tabBarController(self)
    }
    
    func itemButtonAnimationType(with tag: Int) -> WWFloatingActionButton.AnimationType {
        
        guard let buttonType = FloatingActionButtonTag(rawValue: tag) else { return .up(isTextMirror: false) }
        
        switch buttonType {
        case .left: return .up(isTextMirror: true)
        case .right: return .down(isTextMirror: false)
        }
    }
    
    func itemButtonImages(with tag: Int) -> [UIImage] {
        let images = [#imageLiteral(resourceName: "plus"), #imageLiteral(resourceName: "power"), #imageLiteral(resourceName: "refresh"), #imageLiteral(resourceName: "play"), #imageLiteral(resourceName: "chart")]
        return images
    }
    
    func itemButtonTexts(with tag: Int) -> [String] {
        return ["OPEN", "SHARE", "INFO", "CLOSE", "ADD"]
    }
    
    func itemButtonTextsFont(with tag: Int) -> UIFont {
        return UIFont.systemFont(ofSize: 32)
    }
    
    func itemButtonTextsColor(with tag: Int) -> UIColor {
        return .red
    }
    
    func mainButtonStatus(isTouched: Bool, with tag: Int) {
        statusImageView.image = isTouched ? #imageLiteral(resourceName: "LightOn") : #imageLiteral(resourceName: "LightOff")
    }
    
    func itemButton(with tag: Int, didTouched index: Int) {
        let images = [#imageLiteral(resourceName: "desktop_1"), #imageLiteral(resourceName: "desktop_2"), #imageLiteral(resourceName: "desktop_5"), #imageLiteral(resourceName: "desktop_3"), #imageLiteral(resourceName: "desktop_4")]
        myImageView.image = images[index]
    }
}