/
SkinImageView.m
executable file
·60 lines (53 loc) · 1.28 KB
/
SkinImageView.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
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// SkinImageView.m
// WeiboCloned
//
// Created by 赵 福成 on 14-6-25.
// Copyright (c) 2014年 ZhaoFucheng. All rights reserved.
//
#import "SkinImageView.h"
#import "SkinsManager.h"
@implementation SkinImageView
- (id)initWithImageName:(NSString *)imageName
{
self = [self init];
if (self) {
self.imageName = imageName;
}
return self;
}
- (id)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(skinNotification:) name:kSkinDidChangeNotification object:nil];
}
return self;
}
- (void)skinNotification:(NSNotification *)notification
{
[self loadImage];
}
- (void)loadImage
{
if (self.imageName == nil) {
return;
}
UIImage *image = [[SkinsManager shareInstance] getSkinImage:self.imageName];
image = [image stretchableImageWithLeftCapWidth:self.leftCapWidth topCapHeight:self.topCapHeight];
self.image = image;
}
- (void)setImageName:(NSString *)imageName
{
if (_imageName != imageName) {
[_imageName release];
_imageName = [imageName copy];
}
[self loadImage];
}
- (void)dealloc
{
[super dealloc];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kSkinDidChangeNotification object:nil];
}
@end