forked from rangeles/tgCid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageLabel.m
47 lines (36 loc) · 1.13 KB
/
ImageLabel.m
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
#import "ImageLabel.h"
#import "ConstrictedUILabel.h"
#import "UIView-Center.h"
#define IMAGELABEL_SPACING 7
@implementation ImageLabel
- (id)initWithFrame:(CGRect)frame withImage:(UIImage *)aImage {
if ((self = [super initWithFrame:frame])) {
[self setOpaque:NO];
[self setAlpha:0];
image = [[UIImageView alloc] initWithImage:aImage];
[self addSubview:image];
label = [[ConstrictedUILabel alloc] initWithFrame:CGRectMake([image frame].size.width + IMAGELABEL_SPACING, 0, 0, 0)];
[label setConstrictedWidth:([self frame].size.width - [image frame].size.width - IMAGELABEL_SPACING)];
[self addSubview:label];
}
return self;
}
- (void)dealloc {
[image release];
[label release];
[super dealloc];
}
- (void)layoutSubviews {
for (UIView *subview in [self subviews]) {
[subview centerHorizontalAxis];
}
}
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake([label frame].origin.x + [label frame].size.width, size.height);
}
- (void)setLabel:(NSString *)aLabel {
[label setText:aLabel];
[label sizeToFit];
[self sizeToFit];
}
@end