单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
//  ICCommonItemCell.m
//  ICStaticPage
//
// github地址:https://github.com/corderguo/StaticPage
//
//  Created by Mr.Guo on 15/5/28.
//  Copyright © 2016年 XianZhuangGuo. All rights reserved.
//
 
#import "ICCommonItemCell.h"
#import "GloriaLabel.h"
 
@interface ICCommonItemCell ()
 
@property (nonatomic, strong) UIImageView *accessoryImageV;
@property (nonatomic, strong) UISwitch *switchV;
 
 
@end
 
@implementation ICCommonItemCell
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle  = UITableViewCellSelectionStyleNone;
    }
    return self;
}
 
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID     = @"ICStaticPageCell";
    
    ICCommonItemCell *cell  = [tableView dequeueReusableCellWithIdentifier:ID];
    if (nil == cell) {
        cell = [[ICCommonItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
 
- (void)setItem:(ICCommonItem *)item
{
    _item = item;
    
    [self setupData];
    
    [self setUpAccessoryView];
}
 
- (void)setupData
{
    if (_item.icon)
    {
        self.imageView.image = [UIImage imageNamed:_item.icon];
    }
    
    self.textLabel.text     = _item.title;
    
    if(_item.detail && self._nameLabel == nil)
    {
        self._nameLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-SCREEN_WIDTH/2-30, 0,SCREEN_WIDTH/2, 45)];
        self._nameLabel.font = [UIFont systemFontOfSize:16];
        self._nameLabel.textAlignment = UITextAlignmentRight;
        self._nameLabel.textColor = [UIColor redColor];
        
 
        [self.contentView addSubview:self._nameLabel];
    }
    
    self._nameLabel.text = _item.detail;
}
 
- (void)setUpAccessoryView
{
    if ([_item isKindOfClass:[ICSettingArrowItem class]]) { // Arrow
        self.accessoryView = self.accessoryImageV;
    }else if ([_item isKindOfClass:[ICSettingSwitchItem class]]){ // Switch
        self.accessoryView = self.switchV;
    }else{
        self.accessoryView = nil;
    }
}
 
- (void)layoutSubviews
{
    [super layoutSubviews];
}
 
#pragma mark - Event
 
- (void)switchChanged:(UISwitch *)swic
{
    if ([self.delegate respondsToSelector:@selector(commonItemCell:swith:)]) {
        [self.delegate commonItemCell:self swith:swic];
    }
}
 
#pragma mark - Getter
 
- (UISwitch *)switchV
{
    if (nil == _switchV) {
        
        _switchV = [[UISwitch alloc] init];
        [_switchV addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
    }
    return _switchV;
}
 
- (UIImageView *)accessoryImageV
{
    if (nil == _accessoryImageV) {
        _accessoryImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"App_rightArrow"]];
    }
    return _accessoryImageV;
}
 
 
@end