Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 126 lines (96 sloc) 4.536 kB
a8bce05 @WH-NewMedia Add wh-app-ios files.
WH-NewMedia authored
1 /*
2 * This project constitutes a work of the United States Government and is
3 * not subject to domestic copyright protection under 17 USC § 105.
4 *
5 * However, because the project utilizes code licensed from contributors
6 * and other third parties, it therefore is licensed under the MIT
7 * License. http://opensource.org/licenses/mit-license.php. Under that
8 * license, permission is granted free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the conditions that any appropriate copyright notices and this
15 * permission notice are included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 //
28 // WHPhotoAlbumScrollView.m
29 // WhiteHouseApp
30 //
31 //
32
33 #import "WHCaptionedPhotoView.h"
34
35
36 @interface WHCaptionedPhotoView ()
37 @property (nonatomic, strong) UIView *captionWell;
38 @property (nonatomic, strong) UILabel *captionLabel;
39 @end
40
41
42 @implementation WHCaptionedPhotoView
43
44 @synthesize captionWell = _captionWell;
45 @synthesize captionLabel = _captionLabel;
46
47
48 static UIEdgeInsets kWellPadding;
49
50
51 + (void)initialize
52 {
53 // bottom padding takes toolbar into account
54 kWellPadding = UIEdgeInsetsMake(8, 8, 44 + 8, 8);
55 }
56
57
58 - (id)initWithFrame:(CGRect)frame {
59 if ((self = [super initWithFrame:frame])) {
60 self.captionWell = [[UIView alloc] initWithFrame:self.bounds];
61 _captionWell.autoresizingMask = (UIViewAutoresizingFlexibleWidth
62 | UIViewAutoresizingFlexibleTopMargin);
63 _captionWell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.75];
64
65 self.captionLabel = [[UILabel alloc] initWithFrame:self.bounds];
66 _captionLabel.backgroundColor = [UIColor clearColor];
67 _captionLabel.lineBreakMode = UILineBreakModeTailTruncation;
68 _captionLabel.numberOfLines = 0;
69 _captionLabel.font = [WHStyle detailFontWithSize:12];
70 _captionLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
71 _captionLabel.shadowOffset = CGSizeMake(0, 1);
72 _captionLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];
73
74 UIView* topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 1)];
75 topLine.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
76 topLine.backgroundColor = [UIColor darkGrayColor];
77
78
79 [_captionWell addSubview:topLine];
80 [_captionWell addSubview:_captionLabel];
81 [self addSubview:_captionWell];
82 }
83
84 return self;
85 }
86
87
88 - (void)layoutSubviews {
89 [super layoutSubviews];
90
91 CGFloat availableWidth = self.bounds.size.width - kWellPadding.left - kWellPadding.right;
92
93 CGSize labelSize = [self.captionLabel.text sizeWithFont:self.captionLabel.font
94 constrainedToSize:CGSizeMake(availableWidth, CGFLOAT_MAX)
95 lineBreakMode:self.captionLabel.lineBreakMode];
96 CGFloat wellHeight = labelSize.height + kWellPadding.top + kWellPadding.bottom;
97 self.captionWell.frame = CGRectMake(0, self.bounds.size.height - wellHeight,
98 self.bounds.size.width, wellHeight);
99 self.captionLabel.frame = UIEdgeInsetsInsetRect(self.captionWell.bounds, kWellPadding);
100 }
101
102
103 - (void)setCaption:(NSString *)text
104 {
105 if (_captionLabel.text != text) {
106 _captionLabel.text = text;
107 [self setNeedsLayout];
108 }
109 }
110
111
112 - (void)setCaptionHidden:(BOOL)hidden animated:(BOOL)animated
113 {
114 if (animated) {
115 [UIView beginAnimations:NSStringFromClass([self class]) context:nil];
116 }
117
118 _captionWell.alpha = (hidden ? 0.0 : 1.0);
119
120 if (animated) {
121 [UIView commitAnimations];
122 }
123 }
124
125 @end
Something went wrong with that request. Please try again.