- Notifications
You must be signed in to change notification settings - Fork533
Fully customisable tooltip view in Swift for iOS.
License
teodorpatras/EasyTipView
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
EasyTipView
is a fully customizable tooltip view written in Swift that can be used as a call to action or informative tip.
![]() | ![]() |
---|
- Features
- Installation
- Supported OS & SDK versions
- Usage
- Customizing the appearance
- Customising the presentation and dismissal animations
- License
- Contact
- Can be shown pointing to any
UIBarItem
orUIView
subclass. - Support for any arrow direction
←, →, ↑, ↓
- Automatic orientation change adjustments.
- Fully customizable appearance (custom content view or simply just text - including
NSAttributedString
- see the Example app). - Fully customizable presentation and dismissal animations.
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 yourPodfile
:
pod'EasyTipView','~> 2.1'
Then, run the following command:
$ pod install
In case Xcode complains ("Cannot load underlying module for EasyTipView") go to Product and choose Clean (or simply press⇧⌘K).
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage withHomebrew using the following command:
$ brew update$ brew install carthage
To integrate EasyTipView into your Xcode project using Carthage, specify it in yourCartfile
:
github "teodorpatras/EasyTipView"
Runcarthage update
to build the framework and drag the builtEasyTipView.framework
into your Xcode project.
If you prefer not to use either of the aforementioned dependency managers, you can integrate EasyTipView into your project manually.
- Supported build target - iOS 8+ (Xcode 8)
- First you should customize the preferences:
varpreferences=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
- 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 theEasyTipView.globalPreferences
, you can ommit thepreferences
parameter in all calls. Additionally, you can also ommit thewithinSuperview
parameter and theEasyTipView
will be shown within the main application window.
Alternatively, if you want to dismiss theEasyTipView
programmatically later on, you can use one of the instance methods:
lettipView=EasyTipView(text:"Some text", preferences: preferences)tipView.show(forView: someView, withinSuperview: someSuperview)// later on you can dismiss ittipView.dismiss()
In order to customize theEasyTipView
appearance and behavior, you can play with thePreferences
structure which encapsulates all the customizable properties of theEasyTipView
. These preferences have been split into three structures:
Drawing
- encapsulates customizable properties specifying howEastTipView
will be drawn on screen.Positioning
- encapsulates customizable properties specifying whereEasyTipView
will be drawn within its own bounds.Animating
- encapsulates customizable properties specifying howEasyTipView
will animate on and off screen.
Drawing attribute | Description |
---|---|
cornerRadius | The corner radius of the tip view bubble. |
arrowHeight | The height of the arrow positioned at the top or bottom of the bubble. |
arrowWidth | The width of the above mentioned arrow. |
foregroundColor | The text color. |
backgroundColor | The background color of the bubble. |
arrowPosition | The position of the arrow. This can be: + .top : on top of the bubble+ .bottom : at the bottom of the bubble.+ .left : on the left of the bubble+ .right : on the right of the bubble+ .any : use this option to let theEasyTipView automatically find the best arrow position.If the passed in arrow cannot be applied due to layout restrictions, a different arrow position will be automatically assigned. |
textAlignment | The alignment of the text. |
borderWidth | Width of the optional border to be applied on the bubble. |
borderColor | Color of the optional border to be applied on the bubble.In order for the border to be applied,borderColor needs to be different thatUIColor.clear andborderWidth > 0 |
font | Font to be applied on the text. |
shadowColor | The color of the shadow (defaultUIColor.clearcolor ). |
shadowOpacity | The opacity of the shadow (default0 ).For the shadow to be drawn, bothshadowColor andshadowOpacity must be set to a valid value. |
shadowRadius | The radius of the shadow (default0 ). |
shadowOffset | The offset of the shadow. |
Positioning attribute | Description |
---|---|
bubbleHInset | Horizontal bubble inset within its container. |
bubbleVInset | Vertical bubble inset within its container. |
contentHInset | Content horizontal inset within the bubble. |
contentVInset | Content vertical inset within the bubble. |
maxWidth | Max bubble width. |
Animating attribute | Description |
---|---|
dismissTransform | CGAffineTransform specifying how the bubble will be dismissed. |
showInitialTransform | CGAffineTransform specifying the initial transform to be applied on the bubble before it is animated on screen. |
showFinalTransform | CGAffineTransform specifying how the bubble will be animated on screen. |
springDamping | Spring animation damping. |
springVelocity | Spring animation velocity. |
showInitialAlpha | Initial alpha to be applied on the tip view before it is animated on screen. |
dismissFinalAlpha | The alpha to be applied on the tip view when it is animating off screen. |
showDuration | Show animation duration. |
dismissDuration | Dismiss animation duration. |
dismissOnTap | Prevents view from dismissing on tap if it is set to false. (Default value is true.) |
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 theanimating
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=0preferences.animating.showDuration=1.5preferences.animating.dismissDuration=1.5
This produces the following animations:
For more animations, checkout the example project.Once you configured the animations, a good idea would be tomake these preferences global, for all future instances ofEasyTipView
by assigning it toEasyTipView.globalPreferences
.
EasyTipView
is developed byTeodor Patraş and is released under the MIT license. See theLICENSE
file for details.
Logo was created using Bud Icons Launch graphic byBudi Tanrim fromFlatIcon which is licensed underCreative Commons BY 3.0. Made withLogo Maker.
You can follow or drop me a line onmy Twitter account. If you find any issues on the project, you can open a ticket. Pull requests are also welcome.
About
Fully customisable tooltip view in Swift for iOS.