A simple style messages/notifications, in Swift.

Overview

GSMessages

Demo

Example

To show notifications use the following code:

self.showMessage("Something success", type: .success)

To display a notice on a view:

view.showMessage("Something success", type: .success)

To hide a notification manually:

self.hideMessage()

Options (Current setting is default value):

  • type : success / error / warning / info
  • animation : slide(.normal) / slide(.distance(50)) / fade
  • position : top / bottom
  • textAlignment : topLeft / topCenter / topRight / left / center / right / bottomLeft / bottomCenter / bottomRight
self.showMessage("String or NSAttributedString", type: .success, options: [
    .accessibilityIdentifier(nil),
    .animations([.slide(.normal)]),
    .animationDuration(0.3),
    .autoHide(true),
    .autoHideDelay(3.0),
    .cornerRadius(0.0),
    .height(44.0),
    .hideOnTap(true),
    .handleTap({}),
    .isInsideSafeAreaInsets(true),
    .margin(.zero),
    .padding(.init(top: 10, left: 30, bottom: 10, right: 30)),
    .position(.top),
    .textAlignment(.center),
    .textColor(.white),
    .textNumberOfLines(1),
])

Font / Background Color

To set custom fonts and background colors in the following ways:

GSMessage.font = UIFont.boldSystemFont(ofSize: 14)
GSMessage.successBackgroundColor = UIColor(red: 142.0/255, green: 183.0/255, blue: 64.0/255,  alpha: 0.95)
GSMessage.warningBackgroundColor = UIColor(red: 230.0/255, green: 189.0/255, blue: 1.0/255,   alpha: 0.95)
GSMessage.errorBackgroundColor   = UIColor(red: 219.0/255, green: 36.0/255,  blue: 27.0/255,  alpha: 0.70)
GSMessage.infoBackgroundColor    = UIColor(red: 44.0/255,  green: 187.0/255, blue: 255.0/255, alpha: 0.90)

Requirements

Master

  • iOS 8.0+
  • Xcode 11+ (Swift 5.x)

1.7.1

  • iOS 8.0+
  • Xcode 10.0+ (Swift 4.2)

1.5.1

  • iOS 8.0+
  • Xcode 9.0+ (Swift 4.0)

1.3.5

  • iOS 8.0+
  • Xcode 8.0+ (Swift 3.x)

1.2.4

  • iOS 7.0+
  • Xcode 7.3+ (Swift 2.x)

Installation

CocoaPods:

In your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod "GSMessages"

And in your *.swift:

import GSMessages

Carthage:

In your Cartfile:

github "wxxsw/GSMessages"

And in your *.swift:

import GSMessages

License

GSMessages is available under the MIT license. See the LICENSE file for more info.

Comments
  • Position margin

    Position margin

    Thanks for this awesome tool! Now, more than an issue, this would be kind of a suggestion.

    It would be great if we could specify a top, right, left and/or bottom margin to the message view, because in my case, I have a view on the top of the screen. I have also a view on background so I could use the view.showMessage(...) method, but the problem is that this view lays behind the top view, not below, so the message would appear on the absolute top of screen, not below the top view.

    Thanks!

    opened by rserentill 8
  • UITableViewController

    UITableViewController

    Hi.

    I am using GSMessages in a lot of my projects and I really appriciate your work.

    In one of my projects I noticed that if I create a GSMessage in a table view (after some debugging) the height variable is 20px more if I use it in a UITableView compared by another view. If I choose to use the position .Bottom it actually shows the message out of sight.

    Is it possible to fix that?

    Regards Eirik

    opened by eirikmadland 7
  • Type 'String' has no member 'font'

    Type 'String' has no member 'font'

    I got error in this part I'm using Xcode 9 with swift 4

    let attributedText = NSAttributedString(
                string: text,
                attributes: [
                    .font: GSMessage.font,
                    .foregroundColor: UIColor.white,
                    .paragraphStyle: NSParagraphStyle()
                ]
            )
    
    opened by MarsXan 6
  • modify calculatePosition and add option border

    modify calculatePosition and add option border

    1. Modify calculatePosition function for isInsideSafeAreaInsets and inViewController.
    2. Add option, border for messageView

    Please check this! :) And happy for your day.

    opened by eugenejeonme 5
  • Not working correctly when using on presentingViewController

    Not working correctly when using on presentingViewController

    Hi there!

    I'm having an issue when I'm trying to display a message on the presentingViewController, the issue is that the height of the alert is the size of the navigation bar instead of the navigation bar height + additional height.

    Do you know how to solve this?

    opened by leonardodgl 5
  • Improvements for top-positioned message

    Improvements for top-positioned message

    • Fixed bug when message goes out of screen when iOS keyboard appears.
    • Fixed bug when message is not visible after showMessage call with visible iOS keyboard (message placed out of visible screen frame).
    opened by shkoliar 4
  • About orientation

    About orientation

    I've noticed something I wouldn't call a issue, but a possible improvement:

    After a message is displayed, if the user changes his iPhone orientation the displayed message is not being "resized and replaced" to fit to device's new orientation. Do you think it's something you'll be working on in the future? Maybe, if you won't, I could study your code and try to create this improvement, after I finish my current project (which's deadline is very soon)

    opened by leandrodestro 4
  • Fix and improvement

    Fix and improvement

    • Fix of top message positioning for cases when application keyboard do not change inView position.
    • Added automatic message height calculation for multiline mode .textNumberOfLines(0)
    opened by shkoliar 3
  • Problem with updating GSMessages with Carthage under Xcode 8

    Problem with updating GSMessages with Carthage under Xcode 8

    Hello, when I try to update my project with using Carthage for Swift 3 (under Xcode 8) I always get following error:

    `*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace 2016-09-20 11:19:24.122 xcodebuild[20966:120977] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:19:24.124 xcodebuild[20966:120977] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:19:24.124 xcodebuild[20966:120977] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:19.886 xcodebuild[21362:122725] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:19.887 xcodebuild[21362:122725] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:19.888 xcodebuild[21362:122725] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs *** Building scheme "GSMessages" in GSMessages.xcodeproj 2016-09-20 11:20:51.261 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:51.262 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:51.263 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs ** CLEAN FAILED **

    The following build commands failed: Check dependencies (1 failure) ** BUILD FAILED **

    The following build commands failed: Check dependencies (1 failure) A shell task (/usr/bin/xcrun xcodebuild -project /Users/admin/Documents/Projects/Volvo/DealerLocatoriOSGit/Network/Carthage/Checkouts/GSMessages/GSMessages.xcodeproj -scheme GSMessages -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65: 2016-09-20 11:20:51.261 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:51.262 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin' not present in DVTPlugInCompatibilityUUIDs 2016-09-20 11:20:51.263 xcodebuild[21431:123291] [MT] PluginLoading: Required plug-in compatibility UUID 8A66E736-A720-4B3C-92F1-33D9962C69DF for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs ** CLEAN FAILED **

    The following build commands failed: Check dependencies (1 failure) ** BUILD FAILED **

    The following build commands failed: Check dependencies (1 failure)`

    Do you know what can cause the issue? I believe that this message

    GSMessages -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:

    somehow indicates the issue, but it tells nothing specific. Do you know if GSMessage can cause the issue?

    opened by lwalukie 3
  • Fixed message height for multi lines.

    Fixed message height for multi lines.

    Not sure what's up with the logic behind this line of code. Why divide the textWidth by 2 here?

    Here is an example of a single line message with and without the /2 added. As you can see, the reduced width calculation results in an inaccurate (i.e. over-inflated) height.

    My use of the API is pretty straightforward (default padding and margins):

            self.showMessage(message, type: .success, options: [
                .animations([.slide(.normal)]),
                .animationDuration(0.3),
                .autoHide(true),
                .autoHideDelay(2.0),
                .hideOnTap(true),
                .position(.top),
                .textAlignment(.center),
                .textColor(UIColor.preferredColor(forPreferredColorType: .messageText)),
                .textNumberOfLines(0)
            ])
    
    message-bug
    opened by terryworona 2
  • GSMessages adapts dynamically with the size of the text

    GSMessages adapts dynamically with the size of the text

    I had an issue with GSMessages, when the text is too large the GSMessage view trims my text so I added a few lines of code to make GSMessage adapts dynamically with any size of text

    opened by YoussefMostafa 2
Owner
Gesen
———————————————
Gesen
💌 Easy to use and customizable messages/notifications for iOS à la Tweetbot

Notice: TSMessages is no longer being maintained/updated. We recommend everyone migrate to RMessage. This repository will be kept as is for those who

Felix Krause 4.9k Dec 31, 2022
Simple Swift in-app notifications

LNRSimpleNotifications TSMessages is an amazingly powerful in-app notifications library but requires a lot of setup. LNRSimpleNotifications is a simpl

LISNR 203 Nov 20, 2022
SwiftOverlays is a Swift GUI library for displaying various popups and notifications

SwiftOverlays is a Swift GUI library for displaying various popups and notifications. SwiftOverlays animated logo is kindly made by Crafted Pixels Fea

Peter Prokop 632 Dec 22, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022
CoffeeToast - A swift package to easily add Toast notifications to your app

CoffeeToast A simple Swift package to add Toast Notifications to your app. Insta

Maegan Wilson 2 Feb 3, 2022
[iOS] Easy, customizable notifications displayed on top of the statusbar. With progress and activity. iPhone X ready.

JDStatusBarNotification Show messages on top of the status bar. Customizable colors, font and animation. Supports progress display and can show an act

M Emrich 3.8k Dec 27, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

donggyu 5 Jan 26, 2022
A Swift Toast view - iOS 14 style and newer - built with UIKit. 🍞

Toast-Swift A Swift Toast view - iOS 14 style - built with UIKit. ?? Installation Swift Package Manager You can use The Swift Package Manager to insta

Bastiaan Jansen 216 Jan 4, 2023
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
Bulletin / 'Toast' style view for tvOS.

KBBulletinView Bulletin / 'Toast' style view for tvOS. This project is an effort to create local application notifications/alerts similar to those use

Kevin Bradley 4 Nov 26, 2022
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

Kyohei Ito 397 Dec 6, 2022
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 2022
Lightweight dropdown message bar in Swift. It's simple and beautiful.

SwiftyDrop SwiftyDrop is a lightweight pure Swift simple and beautiful dropdown message. Features Easy to use like: Drop.down("Message") Message field

Morita Naoki 691 Nov 20, 2022
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022
😍A simple NoticeBar written by Swift 3, similar with QQ notice view.

NoticeBar ?? A simple NoticeBar written by Swift 3, similar with QQ notice view. ?? ScreenShots Remember: If you want the status bar style change, you

Qiun Cheng 235 Sep 9, 2022
A Simple Customizable Alert With Swift

SimpleCustomizableAlert trying to make my very first library. Support Title Message (TextView) Image TextField Button Action Example let alert

null 1 Oct 26, 2021
BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

Adam Foot 341 Dec 15, 2022
🌊 - Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexible API.

Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexibl

Sebastian Boldt 2.4k Dec 25, 2022