Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (112 sloc) 4.804 kb
880227a @ettore function to do a snapshot of a view appending a title below it
authored
1 /*
2 Copyright (c) 2011, Cubelogic. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 * Neither the name of Cubelogic nor the names of its contributors may be
13 used to endorse or promote products derived from this software without
14 specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27
28 Created by Ettore Pasquini on 10/19/11.
29
30 */
31
32 #import <QuartzCore/QuartzCore.h>
33 #import "clcg_gfx.h"
34
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
35
cf28ce9 @ettore safe_remove_from_superview helper function
authored
36 void clcg_safe_remove_from_superview(id view)
37 {
38 if (view && [view isKindOfClass:[UIView class]] && [view superview]) {
39 [view removeFromSuperview];
40 }
41 }
42
43
8696505 @ettore line wrap, center title, label transparency, etc
authored
44 //TODO-XX make font name and height parameters
880227a @ettore function to do a snapshot of a view appending a title below it
authored
45 UIImage *clcg_do_snapshot(UIView *v, NSString *title)
46 {
47 // make space for the title below the view
8696505 @ettore line wrap, center title, label transparency, etc
authored
48 const CGFloat TITLEH = 80.0;
880227a @ettore function to do a snapshot of a view appending a title below it
authored
49 CGSize sz = v.frame.size;
8696505 @ettore line wrap, center title, label transparency, etc
authored
50 sz.height += TITLEH;
880227a @ettore function to do a snapshot of a view appending a title below it
authored
51
52 // add a label with the title to the view (below it)
8696505 @ettore line wrap, center title, label transparency, etc
authored
53 CGRect titlerect = CGRectMake(4, v.frame.size.height+1, sz.width-4, TITLEH-1);
880227a @ettore function to do a snapshot of a view appending a title below it
authored
54 UILabel *l = [[UILabel alloc] initWithFrame:titlerect];
8696505 @ettore line wrap, center title, label transparency, etc
authored
55 [l setFont:[UIFont fontWithName:@"TrebuchetMS" size:14]];
56 [l setNumberOfLines:0];
2dd694f @ettore fix rendering glitches in tableviews and deprecations introduced by i…
authored
57 [l setTextAlignment:NSTextAlignmentCenter];
58 [l setLineBreakMode:NSLineBreakByWordWrapping];
880227a @ettore function to do a snapshot of a view appending a title below it
authored
59 [l setText:title];
8696505 @ettore line wrap, center title, label transparency, etc
authored
60 [l setBackgroundColor:[UIColor clearColor]];
880227a @ettore function to do a snapshot of a view appending a title below it
authored
61 [v addSubview:l];
62 [l setNeedsLayout];
63 [l setNeedsDisplay];
64
65 // take snapshot
66 UIGraphicsBeginImageContext(sz);
67 CGContextRef ctx = UIGraphicsGetCurrentContext();
68 [v.layer renderInContext:ctx];
69 UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
70 UIGraphicsEndImageContext();
71
72 // cleanup
73 [l removeFromSuperview];
9328ea2 @ettore convert all files to ARC
authored
74
880227a @ettore function to do a snapshot of a view appending a title below it
authored
75 return snapshot;
76 }
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
77
78
cf97f3e @ettore changed function names to candygirl naming conventions
authored
79 void clcg_pushing_vc_for_hiding(UINavigationController *nc,
80 UIViewController *vc,
c875a6c @ettore made the tab-bar-hiding logic more generic by accepting a function in…
authored
81 clcg_should_hide_vc_f shouldhide_callback)
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
82 {
c875a6c @ettore made the tab-bar-hiding logic more generic by accepting a function in…
authored
83 BOOL is_vc_for_hiding = shouldhide_callback(vc);
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
84
cf97f3e @ettore changed function names to candygirl naming conventions
authored
85 vc.hidesBottomBarWhenPushed = is_vc_for_hiding;
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
86
87 // controller currently displayed, about to be be superseded
88 UIViewController *curr = [nc topViewController];
cf97f3e @ettore changed function names to candygirl naming conventions
authored
89 if (!is_vc_for_hiding)
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
90 curr.hidesBottomBarWhenPushed = NO;
91 }
92
93
c875a6c @ettore made the tab-bar-hiding logic more generic by accepting a function in…
authored
94 void clcg_popping_vc_from_hiding(UINavigationController *nc,
95 clcg_should_hide_vc_f shouldhide_callback)
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
96 {
97 // this is the controller about to be removed
98 //UIViewController *curr = [nc topViewController];
99
100 NSArray *vcs = [nc viewControllers];
6127c15 @ettore build for arm64 arch in Xcode 6
authored
101 NSUInteger cnt = [vcs count];
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
102 if (cnt >= 2) {
103 UIViewController *prev = [vcs objectAtIndex:cnt-2];
c875a6c @ettore made the tab-bar-hiding logic more generic by accepting a function in…
authored
104 if (shouldhide_callback(prev)) {
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
105 prev.hidesBottomBarWhenPushed = YES;
106 }
107 }
108
109 // now this would be the controller about to be displayed
110 // curr = [nc topViewController];
111 }
112
113
114 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
115 #pragma mark - Spinny
116
cf97f3e @ettore changed function names to candygirl naming conventions
authored
117 UIActivityIndicatorView *clcg_new_spinny(CGFloat size)
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
118 {
119 CGRect f;
120 UIActivityIndicatorView *spinny;
121
122 f = CGRectMake(0.0, 0.0, size, size);
123 spinny = [[UIActivityIndicatorView alloc] initWithFrame:f];
124 [spinny startAnimating];
125 [spinny setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
126 [spinny sizeToFit];
127 [spinny setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin |
128 UIViewAutoresizingFlexibleRightMargin |
129 UIViewAutoresizingFlexibleTopMargin |
130 UIViewAutoresizingFlexibleBottomMargin)];
131 return spinny;
132 }
133
134
cf97f3e @ettore changed function names to candygirl naming conventions
authored
135 void clcg_attach_spinny2cell(CGFloat size, UITableViewCell *cell)
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
136 {
137 UIActivityIndicatorView *spinny;
138
cf97f3e @ettore changed function names to candygirl naming conventions
authored
139 spinny = clcg_new_spinny(size);
4024ce9 @ettore added methods to show/hide bottom bar when pushing/popping a vc, plus…
authored
140 [cell setAccessoryView:spinny];
141 }
142
Something went wrong with that request. Please try again.