使用 SwiftUI 创建的易于自定义的浮动按钮菜单
浮动按钮
使用 SwiftUI 创建的易于自定义的浮动按钮菜单
我们是一家开发机构,致力于构建非凡的应用程序。
用法
-
创建主按钮视图和许多子菜单按钮 — 两者都应转换为类型。
AnyView
-
将两者传递给构造函数:
FloatingButton
FloatingButton(mainButtonView: mainButton, buttons: buttons)
-
You may also pass a binding which will determine if the menu is currently open. You may use this to close the menu on any submenu button tap for example.
FloatingButton(mainButtonView: mainButton, buttons: buttons, isOpen: $isOpen)
- Chain or to specify desired menu type.
.straight()
.circle()
- Chain whatever you like afterwards. For example:
FloatingButton(mainButtonView: mainButton, buttons: textButtons) .straight() .direction(.top) .alignment(.left) .spacing(10) .initialOffset(x: -1000) .animation(.spring()) FloatingButton(mainButtonView: mainButton2, buttons: buttonsImage.dropLast()) .circle() .startAngle(3/2 * .pi) .endAngle(2 * .pi) .radius(70)
Universal options
spacing
– space between submenu buttons
– size multiplyer for submenu buttons when the menu is closed
– offset for submenu buttons when the menu is closed
– opacity for submenu buttons when the menu is closed
– custom SwiftUI animation like or
– delay for each submenu button’s animation startinitialScaling
initialOffset
initialOpacity
animation
Animation.easeInOut()
Animation.spring()
delays
Straight menu only options
direction
– position of submenu buttons relative to main menu button
– alignment of submenu buttons relative to main menu buttonalignment
Circle only options
startAngle
endAngle
radius
Examples
To try out the FloatingButton examples:
- Clone the repo .
git clone [email protected]:exyte/FloatingButton.git
- Open terminal and run .
cd <FloatingButtonRepo>/Example
- Run to install all dependencies.
pod install
- Run to open project in the Xcode.
xed .
- Try it!
Installation
CocoaPods
pod 'FloatingButton'
Carthage
github "Exyte/FloatingButton"
Manually
Drop FloatingButton.swift into your project.
Requirements
- iOS 13+ / watchOS 13+ / tvOS 13+ / macOS 10.15+
- Xcode 11+