{"id":2408,"url":"https://github.com/zekunyan/TTGSnackbar","last_synced_at":"2025-08-02T23:33:26.938Z","repository":{"id":37451063,"uuid":"43762593","full_name":"zekunyan/TTGSnackbar","owner":"zekunyan","description":"TTGSnackbar shows simple message and action button on the bottom or top of the screen with multi kinds of animation, which is written in Swift3 and inspired by Snackbar in Android. It also support showing custom view, icon image or multi action button.","archived":false,"fork":false,"pushed_at":"2024-03-26T04:57:05.000Z","size":3180,"stargazers_count":644,"open_issues_count":3,"forks_count":103,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-05-17T20:01:21.464Z","etag":null,"topics":["animation","carthage","ios","snackbar","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zekunyan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["zekunyan"]}},"created_at":"2015-10-06T16:21:07.000Z","updated_at":"2024-05-08T08:31:25.000Z","dependencies_parsed_at":"2024-04-24T11:01:30.993Z","dependency_job_id":"a5a2ed87-0183-48e9-a6f7-9cfa60ebc89d","html_url":"https://github.com/zekunyan/TTGSnackbar","commit_stats":{"total_commits":220,"total_committers":31,"mean_commits":7.096774193548387,"dds":"0.36818181818181817","last_synced_commit":"387a3796f0fadcfe00b4588c74e6b5b1204cefbf"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekunyan%2FTTGSnackbar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekunyan%2FTTGSnackbar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekunyan%2FTTGSnackbar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekunyan%2FTTGSnackbar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zekunyan","download_url":"https://codeload.github.com/zekunyan/TTGSnackbar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228503204,"owners_count":17930538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","carthage","ios","snackbar","swift"],"created_at":"2024-01-05T20:16:13.013Z","updated_at":"2024-12-06T17:31:04.038Z","avatar_url":"https://github.com/zekunyan.png","language":"Swift","funding_links":["https://github.com/sponsors/zekunyan"],"categories":["UI","Swift"],"sub_categories":["Alert \u0026 Action Sheet","Other free courses"],"readme":"# TTGSnackbar\nA Swift based implementation of the Android Snackbar for iOS\n\n[![Build Status](https://travis-ci.org/zekunyan/TTGSnackbar.svg?branch=master)](https://travis-ci.org/zekunyan/TTGSnackbar)\n[![Version](https://img.shields.io/cocoapods/v/TTGSnackbar.svg?style=flat)](https://github.com/zekunyan/TTGSnackbar)\n[![License](https://img.shields.io/cocoapods/l/TTGSnackbar.svg?style=flat)](https://github.com/zekunyan/TTGSnackbar)\n[![Platform](https://img.shields.io/cocoapods/p/TTGSnackbar.svg?style=flat)](https://github.com/zekunyan/TTGSnackbar)\n[![Swift5](https://img.shields.io/badge/Swift-5-orange.svg)](https://developer.apple.com/swift)\n[![Apps Using](https://img.shields.io/badge/Apps%20Using-%3E%20787-blue.svg)](https://github.com/zekunyan/TTGSnackbar)\n[![Total Download](https://img.shields.io/badge/Total%20Download-%3E%2036,840-blue.svg)](https://github.com/zekunyan/TTGSnackbar)\n\n![Screenshot](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/screen_shot.png)\n\n# Gif\n\n![Screenshot](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_example.gif)\n\n# About\nTTGSnackbar is useful for showing a brief message at bottom or top of the screen with one or two action buttons.\nIt appears above all other elements on screen.  \nIt disappears after a timeout or after user click the action button.\n\n# Installation\n\n### Swift 5\nVersion 1.9.0+\nXcode 9+\niOS 8+\n\n### Swift 4\nVersion 1.6.0\nXcode 9  \niOS 8+\n\n### Swift 3 \nVersion 1.5.3\nXcode 8  \niOS 8+\n\n### CocoaPods\nYou can use [CocoaPods](http://cocoapods.org) to install `TTGSnackbar` by adding it to your `Podfile`:\n\n```ruby\npod \"TTGSnackbar\"\n```\n\n### Carthage\nYou can use [Carthage](https://github.com/Carthage/Carthage) to install `TTGSnackbar` by adding it to your `Cartfile`:\n```\ngithub \"zekunyan/TTGSnackbar\"\n```\n\n### Import\n\nAnd you need to import the module.  \n```\nimport TTGSnackbar\n```\n\n# Usage\n## Show a simple message\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_1.png)\n```\nlet snackbar = TTGSnackbar(message: \"TTGSnackbar !\", duration: .short)\nsnackbar.show()\n```\n## Show a simple message with an action button\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_2.png)\n```\nlet snackbar = TTGSnackbar(\n    message: \"TTGSnackBar !\",\n    duration: .middle,\n    actionText: \"Action!\",\n    actionBlock: { (snackbar) in\n        print(\"Click action!\")\n    }\n)\nsnackbar.show()\n```\n\n## Show a simple message with a long running action\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_3.png)\n```\nlet snackbar = TTGSnackbar(\n    message: \"TTGSnackbar !\",\n    duration: .forever,\n    actionText: \"Action\",\n    actionBlock: { (snackbar) in\n        print(\"Click action!\")\n        // Dismiss manually after 3 seconds\n        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(3 * Double(NSEC_PER_SEC))) / Doubl(NSEC_PER_SEC)) {\n            snackbar.dismiss()\n        }   \n    }\n)\nsnackbar.show()\n```\n\n## Show a simple message with two action buttons\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_4.png)\n```\nlet snackbar = TTGSnackbar(message: \"Two actions !\", duration: .long)\n\n// Action 1\nsnackbar.actionText = \"Yes\"\nsnackbar.actionTextColor = UIColor.green\nsnackbar.actionBlock = { (snackbar) in NSLog(\"Click Yes !\") }\n\n// Action 2\nsnackbar.secondActionText = \"No\"\nsnackbar.secondActionTextColor = UIColor.yellow\nsnackbar.secondActionBlock = { (snackbar) in NSLog(\"Click No !\") }\n\nsnackbar.show()\n```\n\n## Show a simple message with an icon image\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_5.jpg)\n```\nlet snackbar = TTGSnackbar(message: \"TTGSnackbar !\", duration: .long)\n\n// Add icon image\nsnackbar.icon = UIImage(named: \"emoji_cool_small\")\n\nsnackbar.show()\n```\n\n## [Improved!] Show custom content view in snackbar\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_6.png)\n```\n// Instantiate the custom content view\nlet customContentView = UINib(nibName: \"CustomView\", bundle:Bundle.main).instantiate(withOwner: nil, options: nil).first as! UIView?\n\n// Initialize the snackbar with the custom content view\nlet snackbar = TTGSnackbar(customContentView: customContentView, duration: .long)\n\nsnackbar.show()\n```\n\n## Make use of the Gesture recognizers in snackbar\n![Example](https://github.com/zekunyan/TTGSnackbar/raw/master/Resources/snackbar_5.jpg)\n```\nlet snackbar = TTGSnackbar(message: \"TTGSnackbar !\", duration: .long)\n\n// Add icon image\nsnackbar.icon = UIImage(named: \"emoji_cool_small\")\n\n// Add the gesture recognizer callbacks\nssnackbar.onTapBlock = { snackbar in\n    snackbar.dismiss()\n}\n\nsnackbar.onSwipeBlock = { (snackbar, direction) in\n    \n    // Change the animation type to simulate being dismissed in that direction\n    if direction == .right {\n        snackbar.animationType = .slideFromLeftToRight\n    } else if direction == .left {\n        snackbar.animationType = .slideFromRightToLeft\n    } else if direction == .up {\n        snackbar.animationType = .slideFromTopBackToTop\n    } else if direction == .down {\n        snackbar.animationType = .slideFromTopBackToTop\n    }\n    \n    snackbar.dismiss()\n}\n\nsnackbar.show()\n```\n## [New!] Automatic handling of Showing one Snackbar at a time \n\n`TTGSnackbarManager` can handle automatically showing and replacing the presented Snackbars at your screen.\n\n### **Usage**:\n\n**Swift**\n```swift \nlet snackbar = TTGSnackbar(message: \"TTGSnackbar !\", duration: .long)\nTTGSnackbarManager.show(snackbar)\n```\n\n**Objective-c**\n```objective-c\nTTGSnackbar *bar = [[TTGSnackbar alloc] initWithMessage:@\"Bar1\" duration:TTGSnackbarDurationMiddle];\n[bar setDismissBlock:^(TTGSnackbar * snackBar) {\n\t//whatever you want for dismiss\n}];\n[[TTGSnackbarManager shared] showSnackbar: bar];\n```\n\n\n`TTGSnackbarManager` uses the `dismissBlock` property of a snackbar, it does not replace any functionality that you add to the snackbar, rather it just adds its own code to the existing block.\n\n\n# Customization\n\n### Message\n`message: String` defines the message to display. **Supports multi line text.** **Supports updating on the fly.** \n\n### Message text color\n`messageTextColor: UIColor` defines the message text color.\n\n### Message text font\n`messageTextFont: UIFont` defines the message text font.\n\n### Display duration\n`duration: TTGSnackbarDuration`defines the display duration.  \n`TTGSnackbarDuration` : `short`, `middle`, `long` and `forever`.\nWhen you set `forever`, the snackbar will show an activity indicator after user click the action button and you must dismiss the snackbar manually.\n\n### Action title\n`actionText: String` defines the action button title.\n\n### Action title color\n`actionTextColor: UIColor` defines the action button title color.\n\n### Action title font\n`actionTextFont: UIFont` defines the action button title font.\n\n### Action max width\n`actionMaxWidth: CGFloat` defines the action button max width. Min is 44.\n\n### Action text number of lines\n`actionTextNumberOfLines: Int` defines the number of lines of action button title. Default is 1.\n\n### Action callback\n`actionBlock: TTGActionBlock?` will be called when user clicks the action button.\n```\n// TTGActionBlock definition.\npublic typealias TTGActionBlock = (snackbar: TTGSnackbar) -\u003e Void\n```\n\n### Second action title, color, font and callback\n```\nsecondActionText: String  \nsecondActionTextColor: UIColor  \nsecondActionTextFont: UIFont  \nsecondActionBlock: TTGActionBlock?\n```\n\n### Snackbar MaxWidth\n`snackbarMaxWidth: CGFloat` will set the max width of the snackbar if on larger devices you don not want it full width. Default is -1 which is denotes full-width.\n\n### Dismiss callback\n`dismissBlock: TTGDismissBlock?` will be called when snackbar  dismiss automatically or when user click action button to dismiss the snackbar.\n```\n// TTGDismissBlock definition.\npublic typealias TTGDismissBlock = (snackbar: TTGSnackbar) -\u003e Void\n```\n\n### On Tap Gesture callback\n`onTapBlock: TTGActionBlock` will be called when the user taps the snackbar.\n```\n// TTGActionBlock definition.\npublic typealias TTGActionBlock = (snackbar: TTGSnackbar) -\u003e Void\n```\n\n### On Swipe Gesture callback\n`onSwipeBlock: TTGSwipeBlock` will be called when the user swipes on the snackbar\n```\n/// Swipe gesture callback closure\npublic typealias TTGSwipeBlock = (_ snackbar: TTGSnackbar, _ direction: UISwipeGestureRecognizerDirection) -\u003e Void\n```\n\n### Auto Dismissal using Swipe Gestures\n`shouldDismissOnSwipe: Bool` will determine if the snackbar will automatically be dismissed when it's swiped\n```\n/// A property to make the snackbar auto dismiss on Swipe Gesture\npublic var shouldDismissOnSwipe: Bool = false\n```\n\n### Animation type\n`animationType: TTGSnackbarAnimationType` defines the style of snackbar when it show and dismiss.  \n\n`TTGSnackbarAnimationType` : `fadeInFadeOut`, `slideFromBottomToTop`, `slideFromBottomBackToBottom`, `slideFromLeftToRight`,  `slideFromRightToLeft`, `slideFromTopToBottom` and `slideFromTopBackToTop`.\n\nThe default value of `animationType` is `slideFromBottomBackToBottom`, which is the same as Snackbar in Android.\n\n### Animation duration\n`animationDuration: NSTimeInterval` defines the duration of show and hide animation.\n\n### Margins\n`leftMargin: CGFloat`, `rightMargin: CGFloat`, `topMargin: CGFloat` and `bottomMargin: CGFloat` defines the margins of snackbar\n\n### [New!] Custom Content View to follow left and right margins\n`shouldActivateLeftAndRightMarginOnCustomContentView: Bool` will activate the left and right margins if using a `customContentView`\n```\n/// a property to enable left and right margin when using customContentView\npublic var shouldActivateLeftAndRightMarginOnCustomContentView: Bool = false\n```\n\n### Padding (Content inset)\n`contentInset: UIEdgeInsets` defines the padding(content inset) of content in the snackbar. Default is `UIEdgeInsets.init(top: 0, left: 4, bottom: 0, right: 4)`.\n\n### Corner radius\n`cornerRadius: CGFloat` defines the corner radius of snackbar.\n\n### Icon image\n`icon: UIImage` defines the icon image.\n\n### Icon image content mode\n`iconContentMode: UIViewContentMode` defines the content mode of icon imageView.\n\n### [New!] Custom container view\n`containerView: UIView` defines the custom container(super) view for snackbar to show.\n\n### [New!] Custom content view\n`customContentView: UIView?` defines the custom content view to show in the snackbar.\n\n### [New!] Separator line view background color\n`separateViewBackgroundColor: UIColor = UIColor.gray` defines the separator line color.\n\n### ActivityIndicatorViewStyle\n`activityIndicatorViewStyle: UIActivityIndicatorViewStyle` defines the activityIndicatorViewStyle in snackbar.\n\n### ActivityIndicatorView color\n`activityIndicatorViewColor: UIColor` defines the activityIndicatorView color in snackbar.\n\n### Animation SpringWithDamping\n`animationSpringWithDamping: CGFloat` defines the spring animation damping value. Default is 0.7.\n\n### Animation initialSpringVelocity\n`animationInitialSpringVelocity: CGFloat` defines the spring animation initial velocity. Default is 5.\n\n# Contact me\nzekunyan@163.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekunyan%2FTTGSnackbar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzekunyan%2FTTGSnackbar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekunyan%2FTTGSnackbar/lists"}