Home

Awesome

<img src="https://raw.githubusercontent.com/teodorpatras/EasyTipView/master/assets/easytipview.png" alt="EasyTipView: fully customisable tooltip view written in Swift" style="width: 500px;"/>

Swift3 Platform Build Status Version Carthage Compatible License

Description

EasyTipView is a fully customizable tooltip view written in Swift that can be used as a call to action or informative tip.

<img src="https://raw.githubusercontent.com/teodorpatras/EasyTipView/master/assets/easytipview.gif" width="320"><img src="https://raw.githubusercontent.com/teodorpatras/EasyTipView/master/assets/static.png" width="320">

Contents

  1. Features
  2. Installation
  3. Supported OS & SDK versions
  4. Usage
  5. Customizing the appearance
  6. Customising the presentation and dismissal animations
  7. License
  8. Contact

<a name="features"> Features </a>

<a name="installation"> Installation </a>

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate EasyTipView into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'EasyTipView', '~> 2.1'

Then, run the following command:

$ pod install

In case Xcode complains (<i>"Cannot load underlying module for EasyTipView"</i>) go to Product and choose Clean (or simply press <kbd></kbd><kbd></kbd><kbd>K</kbd>).

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate EasyTipView into your Xcode project using Carthage, specify it in your Cartfile:

github "teodorpatras/EasyTipView"

Run carthage update to build the framework and drag the built EasyTipView.framework into your Xcode project.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate EasyTipView into your project manually.

<a name="supported-versions"> Supported OS & SDK Versions </a>

<a name="usage"> Usage </a>

  1. First you should customize the preferences:

var preferences = EasyTipView.Preferences()
preferences.drawing.font = UIFont(name: "Futura-Medium", size: 13)!
preferences.drawing.foregroundColor = UIColor.whiteColor()
preferences.drawing.backgroundColor = UIColor(hue:0.46, saturation:0.99, brightness:0.6, alpha:1)
preferences.drawing.arrowPosition = EasyTipView.ArrowPosition.top

/*
 * Optionally you can make these preferences global for all future EasyTipViews
 */
EasyTipView.globalPreferences = preferences

  1. Secondly call the show(animated: forView: withinSuperview: text: preferences: delegate:) method:
EasyTipView.show(forView: self.buttonB,
withinSuperview: self.navigationController?.view,
text: "Tip view inside the navigation controller's view. Tap to dismiss!",
preferences: preferences,
delegate: self)

Note that if you set the EasyTipView.globalPreferences, you can ommit the preferences parameter in all calls. Additionally, you can also ommit the withinSuperview parameter and the EasyTipView will be shown within the main application window.

Alternatively, if you want to dismiss the EasyTipView programmatically later on, you can use one of the instance methods:


let tipView = EasyTipView(text: "Some text", preferences: preferences)
tipView.show(forView: someView, withinSuperview: someSuperview)

// later on you can dismiss it
tipView.dismiss()

<a name="customising"> Customizing the appearance </a>

In order to customize the EasyTipView appearance and behavior, you can play with the Preferences structure which encapsulates all the customizable properties of the EasyTipView. These preferences have been split into three structures:

Drawing attributeDescription
cornerRadiusThe corner radius of the tip view bubble.
arrowHeightThe height of the arrow positioned at the top or bottom of the bubble.
arrowWidthThe width of the above mentioned arrow.
foregroundColorThe text color.
backgroundColorThe background color of the bubble.
arrowPositionThe position of the arrow. This can be: <br /> + .top: on top of the bubble <br /> + .bottom: at the bottom of the bubble.<br /> + .left: on the left of the bubble <br /> + .right: on the right of the bubble <br /> + .any: use this option to let the EasyTipView automatically find the best arrow position. <br />If the passed in arrow cannot be applied due to layout restrictions, a different arrow position will be automatically assigned.
textAlignmentThe alignment of the text.
borderWidthWidth of the optional border to be applied on the bubble.
borderColorColor of the optional border to be applied on the bubble. In order for the border to be applied, borderColor needs to be different that UIColor.clear and borderWidth > 0
fontFont to be applied on the text.
shadowColorThe color of the shadow (default UIColor.clearcolor).
shadowOpacityThe opacity of the shadow (default 0). For the shadow to be drawn, both shadowColor and shadowOpacity must be set to a valid value.
shadowRadiusThe radius of the shadow (default 0).
shadowOffsetThe offset of the shadow.
Positioning attributeDescription
bubbleHInsetHorizontal bubble inset within its container.
bubbleVInsetVertical bubble inset within its container.
contentHInsetContent horizontal inset within the bubble.
contentVInsetContent vertical inset within the bubble.
maxWidthMax bubble width.
Animating attributeDescription
dismissTransformCGAffineTransform specifying how the bubble will be dismissed.
showInitialTransformCGAffineTransform specifying the initial transform to be applied on the bubble before it is animated on screen.
showFinalTransformCGAffineTransform specifying how the bubble will be animated on screen.
springDampingSpring animation damping.
springVelocitySpring animation velocity.
showInitialAlphaInitial alpha to be applied on the tip view before it is animated on screen.
dismissFinalAlphaThe alpha to be applied on the tip view when it is animating off screen.
showDurationShow animation duration.
dismissDurationDismiss animation duration.
dismissOnTapPrevents view from dismissing on tap if it is set to false. (Default value is true.)

<a name="customising-animations"> Customising the presentation or dismissal animations </a>

The default animations for showing or dismissing are scale up and down. If you want to change the default behavior, you need to change the attributes of the animating property within the preferences. An example could be:

preferences.animating.dismissTransform = CGAffineTransform(translationX: 0, y: -15)
preferences.animating.showInitialTransform = CGAffineTransform(translationX: 0, y: -15)
preferences.animating.showInitialAlpha = 0
preferences.animating.showDuration = 1.5
preferences.animating.dismissDuration = 1.5

This produces the following animations: <br><br><img src="https://raw.githubusercontent.com/teodorpatras/EasyTipView/master/assets/animation.gif" width="200">

For more animations, checkout the example project. Once you configured the animations, a good idea would be to make these preferences global, for all future instances of EasyTipView by assigning it to EasyTipView.globalPreferences.

<a name="license"> License </a>

EasyTipView is developed by Teodor Patraş and is released under the MIT license. See the LICENSE file for details.

Logo was created using Bud Icons Launch graphic by Budi Tanrim from FlatIcon which is licensed under Creative Commons BY 3.0. Made with Logo Maker.

<a name="contact"> Contact </a>

You can follow or drop me a line on my Twitter account. If you find any issues on the project, you can open a ticket. Pull requests are also welcome.