Giter Site home page Giter Site logo

rmessage's Introduction

RMessage

Screenshots

ErrorUnder

SuccessUnder

ErrorOver

WarningOver

Intro

Welcome to RMessage! RMessage is a simple notification library written in Swift to help you display notification on the screen. Many many customization options are available such as what position of the screen to present in, what colors should be applied to the title, body, background, etc, etc. There are many customizable properties and they can be viewed at the RMessageSpec protocol definition

3.0.1 Release

RMessage 3.0.1 is finally here with many new features

  • Rewritten in Swift.
  • Message notification designs are now easily specified in code via the RMessageSpec protocol - no more passing in design styles via a json design file.
  • Support for generic UIViews for the Left/Right/Background of the message. Want to pass a UIButton for the left view or background view? Go ahead.
  • Support for Attributed string stylings.
  • Support for new message duration types such as messages that can only be dismissed by tapping, or swiping, or both.
  • Support for canceling messages already in the queue waiting to be presented.
  • Support for Carthage.
  • Groundwork for custom animator objects via the RMessageAnimator Protocol has been set, support for passing in your own animators coming soon.

Note: RMessage now requires iOS 15.0 and Swift 5.7.

Installation

Usage

To show a simple notification using the predefined "errorSpec" styling, animating from the top do the following:

// Create an instance of RMController, a controller object which handles the presentation
// of multiples messages on the screen
let rControl = RMController()

// Tell rControl to present the message
rControl.showMessage(
      withSpec: errorSpec,
      title: "Your Title",
      body: "A description"
)

To show your own button on the right, an icon (UIImage) on the left and animate from the bottom do this:

let rControl = RMController()
rControl.showMessage(
      withSpec: normalSpec,
      atPosition: .bottom,
      title: "Update available",
      body: "Please update the app",
      leftView: myIconImage,
      rightView: myUIButtonHere
)

To set a default view controller to present in and bypass the "internal presentation view controller detection":

   let rControl = RMController()
   rControl.presentationViewController = myViewController

   ...

   // All messages now presented by this controller will always be on myViewController
   rControl.showMessage(....)

Want to further customize a notification message right before its presented? Do the following:

   let rControl = RMController()
   rControl.delegate = self

   ...

   // Now lets implement the RMControllerDelegate customize(message:controller:) method which
   // RMController calls right before presenting:
   func customize(message: RMessage) {
   message.alpha = 0.4
   message.addSubview(aView)
  }

Feel like declaring your own custom message stylings? Simple!

let rControl = RMController()

// Customize the message, by using the DefaultRMessageSpec as your base.
// The DefaultRMessageSpec object is a struct with default values for a
// "default" RMessageSpec styling. All we need to do is pick up the the defaults
// from it and then just specify which variables we want customized. For a list
// of all the possible vars take a look at its definition!
var customSpec = DefaultRMessageSpec()
customSpec.backgroundColor = .red
customSpec.titleColor = .white
customSpec.bodyColor = .white
customSpec.iconImage = UIImage(named: "MyIcon.png")

// How about a custom spec based on the predefined warningSpec but with
// attributed string attributes for the title and body text?
var attrWarningSpec = warningSpec
attrWarningSpec.titleAttributes = [.backgroundColor: UIColor.red, .foregroundColor: UIColor.white]
attrWarningSpec.bodyAttributes = [
.backgroundColor: UIColor.blue, .foregroundColor: UIColor.white,
.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
]

// Now lets present Tell the RMController to present the message with your custom stylings.
rControl.showMessage(
      withSpec: customSpec,
      title: "I'm custom",
      body: "Nice!"
    )

Want to present a message that only disappers when tapped?

let rControl = RMController()

var tapOnlySpec = DefaultRMessageSpec()
tapOnlySpec.durationType = .tap

// Present it
rControl.showMessage(
      withSpec: tapOnlySpec,
      title: "Tap me Tap me!",
      body: "If you don't I wont dismiss!"
)

Want more examples? Take a look at the Demo directory in the RMessage project to see how to use this library. Its very simple.

License

RMessage is available under the MIT license. See the LICENSE file for more information.

rmessage's People

Contributors

paulvaldes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.