一个实用的 Swift 弹幕工具栏组件,用于在屏幕底部快速显示状态更新和错误。请参阅以它命名的Android 弹幕。
不阻塞主 UI
let snackbar = Snackbar()
view.addSubview(snackbar)
// Start some long-running task...
snackbar.updateWithStatus("Syncing Data", message: "This may take a moment...")
// If/when that task finishes...
snackbar.completeWithStatus("Syncing Complete", message: "Your data seems to all be here.")
// If the tasks fails, you can handle the error like so...
snackbar.updateWithError("Error",
message: error.localizedDescription,
actionOptions: (buttonTitle: "RETRY", statusTitle: "Retrying", statusMessage: "Sit tight...", onSelect: { Void in
// fetchData()
})
)