Skip to content

michaelforrest/EasyTipView

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyTipView

Version License Platform

Purpose

EasyTipView is a custom tooltip view written in Swift that can be used as a call to action or informative tip. It can be presented for any UIBarButtonItem or UIView subclass. In addition it handles automatically orientation changes and will always point to the correct view or item.

Example

Installation

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:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'EasyTipView', '~> 0.1.0'

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

Usage

  1. First you should customize the preferences:
  
  var preferences = EasyTipView.Preferences()
  preferences.bubbleColor = UIColor(hue:0.58, saturation:0.1, brightness:1, alpha:1)
  preferences.textColor = UIColor.darkGrayColor()
  preferences.font = UIFont(name: "HelveticaNeue-Regular", size: 10)
  preferences.textAlignment = NSTextAlignment.Center
  
  1. Secondly you call the showAnimated:forView:withinSuperview:text:preferences:delegate: method:
  EasyTipView.showAnimated(true, 
  forView: self.buttonB, 
  withinSuperview: self.navigationController?.view,
  text: "Tip view inside the navigation controller's view. Tap to dismiss!",
  preferences: preferences,
  delegate: self)

Supported OS & SDK Versions

  • Supported build target - iOS 7.0 (Xcode 6.x)

Custom types

@objc protocol EasyTipViewDelegate {
    func easyTipViewDidDismiss(tipView : EasyTipView)
}

Custom protocol which defines one method to be called on the delegate after the EasyTipView has been dismissed.

struct Preferences {
  var systemFontSize          :   CGFloat                =   15
  var textColor               :   UIColor                =   UIColor.whiteColor()
  var bubbleColor             :   UIColor                =   UIColor.redColor()
  var arrowPosition           :   ArrowPosition          =   .Bottom
  var font                    :   UIFont?
  var textAlignment           :   NSTextAlignment        =   NSTextAlignment.Center
}

Custom structure which encapsulates all the customizable properties of the EasyTipView. If the font is not specified, the tip view will default to the UIFont.systemFontOfSize(preferences.systemFontSize).

enum ArrowPosition {
  case Top
  case Bottom
}

Custom enumeration which defines the position that the bubble arrow can take.

Methods

class func showAnimated(animated : Bool, forView view : UIView, withinSuperview superview : UIView?, text :  NSString, preferences: Preferences?, delegate : EasyTipViewDelegate?)

Call this class method when you want to display the EasyTipView pointing to a UIView subclass. superview parameter is optional. If you do not specify a superview, the EasyTipView will be displayed within the main window.

func showForView(view : UIView, withinSuperview sview : UIView?, animated : Bool)

The same as the above method, only difference is that this is an instance method.

class func showAnimated(animated : Bool, forItem item : UIBarButtonItem, withinSuperview superview : UIView?, text : NSString, preferences: Preferences?, delegate : EasyTipViewDelegate?)

Call this class method when you want to display the EasyTipView pointing to a UIBarButtonItem subclass. superview parameter is optional. If you do not specify a superview, the EasyTipView will be displayed within the main window.

func showForItem(item : UIBarButtonItem, withinSuperView sview : UIView?, animated : Bool)

The same as the above method, only difference is that this is an instance method.

func dismissWithCompletion(completion : ((finished : Bool) -> Void)?)

Use this method to programmatically hide the EasyTipView view.

About

A tooltip view written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 60.8%
  • Shell 34.4%
  • Ruby 2.6%
  • Objective-C 2.2%