项目介绍:
SwiftMessages是一款在在屏幕的顶部或底部状态栏的形式显示简短消息的iOS库
DEMO 下载:
UsageBasics[Objective-C] 查看源文件 复制代码
SwiftMessages.show(view: myView)
Although you can show any instance of UIView, SwiftMessages provides a MessageView classand assortment of nib-based layouts that should handle most cases:
[Objective-C] 查看源文件 复制代码
// Instantiate a message view from the provided card view layout. SwiftMessages searches for nib // files in the main bundle first, so you can easily copy them into your project and make changes. let view = MessageView.viewFromNib(layout: .CardView) // Theme message elements with the warning style. view.configureTheme(.Warning) // Add a drop shadow. view.configureDropShadow() // Set message title, body, and icon. Here, we're overriding the default warning // image with an emoji character. view.configureContent(title: "Warning", body: "Consider yourself warned.", iconText: "") // Show the message. SwiftMessages.show(view: view)
You may wish to use the view provider variant show(viewProvider to ensure thatyour UIKit code is executed on the main queue:
[Objective-C] 查看源文件 复制代码
SwiftMessages.show { let view = MessageView.viewFromNib(layout: .CardView) // ... configure the view return view }
The SwiftMessages.Config struct provides numerous configuration options that can be passed to show():
[Objective-C] 查看源文件 复制代码
var config = SwiftMessages.Config() // Slide up from the bottom. config.presentationStyle = .Bottom // Display in a window at the specified window level: UIWindowLevelStatusBar // displays over the status bar while UIWindowLevelNormal displays under. config.presentationContext = .Window(windowLevel: UIWindowLevelStatusBar) // Disable the default auto-hiding behavior. config.duration = .Forever // Dim the background like a popover view. Hide when the background is tapped. config.dimMode = .Gray(interactive: true) // Disable the interactive pan-to-hide gesture. config.interactiveHide = false // Specify a status bar style to if the message is displayed directly under the status bar. config.preferredStatusBarStyle = .LightContent SwiftMessages.show(config: config, view: view)