This repository has been archived by the owner on Aug 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMPopTipView.h
150 lines (122 loc) · 5.7 KB
/
CMPopTipView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// CMPopTipView.h
//
// Created by Chris Miles on 18/07/10.
// Copyright (c) Chris Miles 2010-2013.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
/*
Version: 2.0
*/
/** \brief Display a speech bubble-like popup on screen, pointing at the
designated view or button.
A UIView subclass drawn using core graphics. Pops up (optionally animated)
a speech bubble-like view on screen, a rounded rectangle with a gradiant
fill containing a specified text message, drawn with a pointer dynamically
positioned to point at the center of the designated button or view.
Example 1 - point at a UIBarButtonItem in a nav bar:
- (void)showPopTipView {
NSString *message = @"Start by adding a waterway to your favourites.";
CMPopTipView *popTipView = [[CMPopTipView alloc] initWithMessage:message];
popTipView.delegate = self;
[popTipView presentPointingAtBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
self.myPopTipView = popTipView;
[popTipView release];
}
- (void)dismissPopTipView {
[self.myPopTipView dismissAnimated:NO];
self.myPopTipView = nil;
}
#pragma mark CMPopTipViewDelegate methods
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
// User can tap CMPopTipView to dismiss it
self.myPopTipView = nil;
}
Example 2 - pointing at a UIButton:
- (IBAction)buttonAction:(id)sender {
// Toggle popTipView when a standard UIButton is pressed
if (nil == self.roundRectButtonPopTipView) {
self.roundRectButtonPopTipView = [[[CMPopTipView alloc] initWithMessage:@"My message"] autorelease];
self.roundRectButtonPopTipView.delegate = self;
UIButton *button = (UIButton *)sender;
[self.roundRectButtonPopTipView presentPointingAtView:button inView:self.view animated:YES];
}
else {
// Dismiss
[self.roundRectButtonPopTipView dismissAnimated:YES];
self.roundRectButtonPopTipView = nil;
}
}
#pragma mark CMPopTipViewDelegate methods
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
// User can tap CMPopTipView to dismiss it
self.roundRectButtonPopTipView = nil;
}
*/
#import <UIKit/UIKit.h>
typedef enum {
PointDirectionAny = 0,
PointDirectionUp,
PointDirectionDown,
} PointDirection;
typedef enum {
CMPopTipAnimationSlide = 0,
CMPopTipAnimationPop
} CMPopTipAnimation;
@protocol CMPopTipViewDelegate;
@interface CMPopTipView : UIView
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, weak) id<CMPopTipViewDelegate> delegate;
@property (nonatomic, assign) BOOL disableTapToDismiss;
@property (nonatomic, assign) BOOL dismissTapAnywhere;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *message;
@property (nonatomic, strong) UIView *customView;
@property (nonatomic, strong, readonly) id targetObject;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, strong) UIFont *titleFont;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, strong) UIFont *textFont;
@property (nonatomic, assign) UITextAlignment titleAlignment;
@property (nonatomic, assign) UITextAlignment textAlignment;
@property (nonatomic, assign) BOOL has3DStyle;
@property (nonatomic, strong) UIColor *borderColor;
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) BOOL hasShadow;
@property (nonatomic, assign) CMPopTipAnimation animation;
@property (nonatomic, assign) CGFloat maxWidth;
@property (nonatomic, assign) PointDirection preferredPointDirection;
@property (nonatomic, assign) BOOL hasGradientBackground;
@property (nonatomic, assign) CGFloat sidePadding;
@property (nonatomic, assign) CGFloat topMargin;
/* Contents can be either a message or a UIView */
- (id)initWithTitle:(NSString *)titleToShow message:(NSString *)messageToShow;
- (id)initWithMessage:(NSString *)messageToShow;
- (id)initWithCustomView:(UIView *)aView;
- (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated;
- (void)presentPointingAtBarButtonItem:(UIBarButtonItem *)barButtonItem animated:(BOOL)animated;
- (void)dismissAnimated:(BOOL)animated;
- (void)autoDismissAnimated:(BOOL)animated atTimeInterval:(NSTimeInterval)timeInvertal;
- (PointDirection) getPointDirection;
@end
@protocol CMPopTipViewDelegate <NSObject>
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView;
@end