Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Fully customisable tooltip view in Swift for iOS.

License

NotificationsYou must be signed in to change notification settings

teodorpatras/EasyTipView

Repository files navigation

EasyTipView: fully customisable tooltip view written in Swift

Swift3PlatformBuild StatusVersionCarthage CompatibleLicense

Description

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

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
  • Can be shown pointing to anyUIBarItem orUIView subclass.
  • Support for any arrow direction←, →, ↑, ↓
  • Automatic orientation change adjustments.
  • Fully customizable appearance (custom content view or simply just text - includingNSAttributedString - see the Example app).
  • Fully customizable presentation and dismissal animations.

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 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 pressK).

Carthage

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.

Manually

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)
  1. 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
  1. Secondly call theshow(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 thepreferencesparameter in all calls. Additionally, you can also ommit thewithinSuperviewparameter and theEasyTipViewwill 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 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:
+.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.
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 thatUIColor.clear andborderWidth > 0
fontFont to be applied on the text.
shadowColorThe color of the shadow (defaultUIColor.clearcolor).
shadowOpacityThe opacity of the shadow (default0).For the shadow to be drawn, bothshadowColorandshadowOpacitymust be set to a valid value.
shadowRadiusThe radius of the shadow (default0).
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.)

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp