-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeButton.m
70 lines (49 loc) · 1.56 KB
/
ThemeButton.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
61
62
63
64
65
66
67
68
69
70
//
// ThemeButton.m
// WeiChi
//
// Created by imac on 15/9/8.
// Copyright (c) 2015年 imac. All rights reserved.
//
#import "ThemeButton.h"
#import "ThemeManager.h"
@implementation ThemeButton
-(void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
//注册监听通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange:) name:kThemeDidChangeNotificationName object:nil];
}
return self;
}
-(void)themeDidChange:(NSNotification *)notification{
//重新加载图片
[self loadImage];
}
-(void)setNormalImageName:(NSString *)normalImageName{
if(![_normalImageName isEqualToString:normalImageName]){
_normalImageName=[normalImageName copy];
[self loadImage];
}
}
-(void)setHighLightImageName:(NSString *)HighLightImageName{
if(![_HighLightImageName isEqualToString:HighLightImageName]){
_HighLightImageName=[HighLightImageName copy];
[self loadImage];
}
}
- (void)loadImage{
ThemeManager *manager=[ThemeManager shareInstance];
UIImage *normalImage=[manager getThemeImage:self.normalImageName];
UIImage *highlightImage=[manager getThemeImage:self.HighLightImageName];
if(normalImage !=nil){
[self setImage:normalImage forState:UIControlStateNormal];
}
if(highlightImage != nil){
[self setImage:highlightImage forState:UIControlStateNormal];
}
}
@end