

GitHub - chriszielinski/Ribbon: 🎀 A simple cross-platform toolbar/custom input a...
source link: https://github.com/chriszielinski/Ribbon
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
Ribbon 🎀
A simple cross-platform toolbar/custom input accessory view library for iOS & macOS.
Written in Swift.
Looking for...
- A type-safe, XPC-available SourceKitten (SourceKit) interface with some sugar? Check out Sylvester 😼.
- A Floating Action Button for macOS? Check out Fab. 🛍️.
- An Expanding Bubble Text Field for macOS? Check out BubbleTextField 💬.
- An integrated spotlight-based onboarding and help library for macOS? Check out Enlighten 💡.
Features
🎡Try: Includes an iOS & macOS demo.
- Provide items either programmatically or from a JSON configuration file.
- Dark mode.
- + more!
iOS
-
Supports push buttons—a segmented item's subitems become push buttons.
-
iOS 13: action items use the new context menu interaction:
macOS
- Supports push, action, & segmented control toolbar items.
- Provides
NSMenuItem
s for each item.
Requirements
- iOS 10.0+ (12.0+ for dark mode)
- macOS 10.12+ (10.13+ for full functionality)
Installation
Ribbon
is available for installation using Carthage or CocoaPods.
Carthage
github "chriszielinski/Ribbon"
CocoaPods
pod "Ribbon"
iOS 13
Building for iOS 13 requires Xcode 11 and modifying iOS13.xcconfig:
// Uncomment to build Ribbon for iOS 13. // // - Note: Requires Xcode 11. SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) IOS13
Usage
There are two ways of integrating Ribbon
into your project:
Configuration File
🔥 The recommended approach.
The configuration file makes for a quick & easy integration. The default configuration filename is ribbon-configuration.json
and should be copied into the target's bundle resources (in the Copy Bundle Resources build phase).
The JSON below defines a single action item and toolbar configuration—which is only relevant for the macOS platform.
🧐 See: Demos/Shared/ribbon-configuration.json for a more comprehensive example.
{ "items": [ { "action": "actionItemHandler", "controlKind": "action", "identifier": "action-item-identifier", "imageName": "NSActionTemplate", "keyEquivalent": "a", "keyEquivalentModifier": ["command", "shift"], "title": "Action Item", "toolTip": "The action button's tool-tip.", "subitems": [ { "action": "firstActionSubitemHandler", "identifier": "first-action-subitem", "imageName": "hand.thumbsup", "keyEquivalent": "1", "keyEquivalentModifier": ["command"], "title": "First Action Subitem", "toolTip": "The first action's tool-tip." }, { "action": "secondActionSubitemHandler", "identifier": "second-action-subitem", "imageName": "hand.thumbsdown", "keyEquivalent": "2", "keyEquivalentModifier": ["command"], "title": "Second Action Subitem", "toolTip": "The second action's tool-tip." } ] } ], "toolbar": { "displayMode": "iconOnly", "sizeMode": "regular", "identifier": "toolbar-identifier", "defaultItems" : ["NSToolbarFlexibleSpaceItem", "action-item-identifier"] } }
Integration into your view controller is as simple as:
📌Note: The code below is an abstraction and will not compile.
import Ribbon class YourViewController ... { ... var ribbon: Ribbon! override func viewDidLoad() { ribbon = try! Ribbon.loadFromMainBundle(target: self) #if canImport(UIKit) textView.inputAccessoryView = ribbon #endif } #if canImport(AppKit) override func viewWillAppear() { view.window?.toolbar = ribbon.toolbar super.viewWillAppear() } #endif @objc func actionItemHandler() { } @objc func firstActionSubitemHandler() { } @objc func secondActionSubitemHandler() { } }
Programmatically
📌Note: The code below is an abstraction and will not compile.
import Ribbon class YourViewController ... { ... var ribbon: Ribbon! override func viewDidLoad() { let firstActionSubitem = RibbonItem(subItemTitle: "First Action Subitem") firstActionSubitem.action = #selector(firstActionSubitemHandler) let secondActionSubitem = RibbonItem(subItemTitle: "Second Action Subitem") secondActionSubitem.action = #selector(secondActionSubitemHandler) let actionItem = RibbonItem(controlKind: .action, title: "Action Item", subitems: [firstActionSubitem, secondActionSubitem]) actionItem.action = #selector(actionItemHandler) ribbon = Ribbon(items: [actionItem], target: self) #if canImport(UIKit) textView.inputAccessoryView = ribbon #endif } #if canImport(AppKit) override func viewWillAppear() { view.window?.toolbar = ribbon.toolbar super.viewWillAppear() } #endif @objc func actionItemHandler() { } @objc func firstActionSubitemHandler() { } @objc func secondActionSubitemHandler() { } }
// ToDo:
- Add documentation.
- Implement
UIKeyCommand
.
Community
- Found a bug? Open an issue.
- Feature idea? Open an issue. Do it yourself & PR when done 😅 (or you can open an issue 🙄).
- Want to contribute? Submit a pull request.
Acknowledgements
- Based on Rudd Fawcett's
RFKeyboardToolbar
.
Contributors
- Chris Zielinski — Original author.
Frameworks & Libraries
Ribbon
depends on the wonderful contributions of the Swift community, namely:
- realm/SwiftLint — A tool to enforce Swift style and conventions.
License
Ribbon
is available under the MIT license, see the LICENSE file for more information.
Recommend
-
73
-
54
声明:代码不是我写的=_= 现象 前两天碰到一个ribbon相关的问题,觉得值得记录一下。表象是对外的接口返回内部异常,这个是封装的统 一错误信息,Spring的异常处理器catch到未捕获异常统一返回的信息。因此到...
-
34
什么是负载均衡器? 假设有一个分布式系统,该系统由在不同计算机上运行的许多服务组成。但是,当用户数量很大时,通常会为服务创建多个副本...
-
41
在微服务架构中,根据业务需求拆分成一个个的微小服务,然后服务与服务之间可以相互RPC远程调用。在SpringCloud可以使用RestTemplate+Ribbon或者Feign来进行RPC远程调用。为了保证服务高可用性,单个服务通常会进行集群部署。由于网络原因或者自身的原因,服务并不...
-
33
点击上方“ 掌上编程 ”,选择“ 置顶或者星标 ” 优质文章第一时间送达! Ribbon [...
-
15
SpringCloud 之 Ribbon/Feign/Hystrix 的超时、重试问题总结 Hi,我是空夜,又是一周不见!今天来讲讲 ribbon 和 feign 中超时时间应该如何配置。Spring Cloud 中,一般会用 feign 或...
-
9
实操演示springcloud怎么用ribbon做负载均衡
-
12
Requirement The customer required that when an item is in a a specific workflow state, the item cannot be edited. Sitecore has a special security permission to achieve this Workflow State Write
-
8
The guys at Netflix have developed and open sourced (among many other things) Feign and Ribbon. These libraries can help you as a developer, to build robust, fault tolerant service integrations. Best of all, they’ve been tested in the wild...
-
6
上一篇在User模块里调用Order的时候用到了一个注解 @LoadBanlance 这货就是Ribbon里的 Ribbon是什么东西? 一个基于Http和TCP的客户端负载均衡工具,它解决的是微服务之间的负载均衡问题,是一个部署在客户端的负载均衡...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK