Coder Social home page Coder Social logo

swipip / shsmarthint Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 142 KB

An easy to use framework that provides convenient way to add banners, callouts and alerts to your controllers.

License: MIT License

Swift 96.43% Objective-C 0.52% Ruby 3.05%
callout banners alerts

shsmarthint's Introduction

SHSmarthint

Build Status

What is it ?

SmartHint is a framework that lets you add banners, callouts or alerts to point out an action to a user. All this views are interactive, customizable and easy to implement with simple properties and callbacks to respond to touch events and button presses. SmartHint is much easier to implement than standard UIKit equivalents, much more flexible and customizable as well for simple tasks.

Basic integration

Add the framework to your project with the following command.

pod 'SmartHint', '~> 1.0.5'

How to use SH core features

First you must import the framework to the file your are working on:

import SmartHint

SmartHint offers a convenient way to add callOut and banners to certain views inside you view hierarchy. To interact with the framework simply use the built in UIViewController extenion

self.sh

Banner

You can create add a banner bellow your UINavigationController's navBar like so:

 guard let targetView = navigationController?.navigationBar else {return}
 sh.addHint(hint: Hint(style: .banner(.bottom), message: "Hey this is a banner"), to: targetView) {
   //Respond to banner view's tap event
 }

An optional completion argument is triggered in reponse to a tap event on the banner.

Callout

You can create add a callout bellow a given view like so:

sh.addHint(hint: Hint(style: .callout(.triangle), message: "Hey this is a callout"), to: targetView) {
 //Respond to banner view's tap event
}

An optional completion argument is triggered in reponse to a tap event on the callout.

Build custom hint

You can create custom hints by using the Hint object's properties

Custom Hint

Change core hint properties like background color, or text color, message or presentation animation style like this:

let hint = Hint(style: .banner(.bottom))
hint.backgroundColor = .white
hint.buttonsColor = .systemGray6
hint.message = "This is my banner's message"
hint.animationStyle = .fromTop

Adding a textField in an AlertView

Uniquely available to alerts, you can choose to display a textField inside the view. The following example shows how to tell SmartHint you need a textField and how to subscribe to its events.

let hint = Hint(style: .alert)
hint.hasTextField = { [weak self] textField in
   textField.delegate = self
   return true
}

The view you are assigning the delegate to must conform to UITextFieldDelegate. Do this like so:

extension YourViewController: UITextFieldDelegate {
    func textFieldDidChangeSelection(_ textField: UITextField) {
        //Respond to changes
    }
}

Adding buttons

To add a button you simply need to pass a completion handler to the addAction(_ action: HintAction) method. Let's say you need to add two buttons:

let hint = Hint(style: .banner(.bottom))
hint.addAction(HintAction(title: "first button", handler: { hint in
    //Do something when the first button gets tapped
}))
hint.addAction(HintAction(title: "second button", handler: { hint in
    //Do something when the second button gets tapped
}))

Note that in the callback you get access to the current associated hint object. This is useful is you need to access specific parameters of the hint such as the optional textfield of an AlertView for instance

Modifying core properties

Should you need to update some of HintViews core properties to fit the layout style to you app's, you cna do using the setDefaultValue(_ value: Any, forKey key: ConstantName) method provided by the SmartHint viewController's extension.

sh.setDefaultValue(CGFloat(12), forKey: .hintViewCornerRadius)
sh.setDefaultValue(CGFloat(8), forKey: .buttonsCornerRadius)

Note that you MUST indicate to right type for the value your are modifying otherwise the module will raise an exception. So for instance provide a CGFloat for view layout related values and a Double for the animation timing for instance

shsmarthint's People

Contributors

swipip avatar

Stargazers

 avatar

Watchers

 avatar  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.