CNLiveNewsDetailsView.m
3.35 KB
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
//
// CNLiveNewsDetailsView.m
// CNLiveScioLive
//
// Created by Xiaowen Zhang on 2018/9/21.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveNewsDetailsView.h"
@interface CNLiveNewsDetailsView()
@property (nonatomic, strong) UILabel *line;
@end
@implementation CNLiveNewsDetailsView
- (instancetype)initWithFrame:(CGRect)frame pics:(NSArray *)pics{
self = [super initWithFrame:frame];
if(self){
_pics = pics;
CGFloat width = MainScreenWidth*1.0/pics.count;
for(int i = 0; i < pics.count; i++){
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(i*width, 0, width, self.bounds.size.height);
btn.tag = 1000+i;
btn.layer.masksToBounds = YES;
[btn setImage:[[UIImage imageNamed:pics[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(clickedBtn:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
}
_line = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, Line_Height)];
_line.backgroundColor = Color_Line;
[self addSubview:_line];
}
return self;
}
-(void)setPics:(NSArray *)pics{
_pics = pics;
CGFloat width = MainScreenWidth*1.0/pics.count;
for(int i = 0; i < pics.count; i++){
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(i*width, 0, width, self.bounds.size.height);
btn.tag = 1000+i;
btn.layer.masksToBounds = YES;
[btn addTarget:self action:@selector(clickedBtn:) forControlEvents:UIControlEventTouchUpInside];
if(i == 1){
self.btn = btn;
TableData *notice = [[TableData alloc] initWithJSONDictionary:self.dic];
BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
if (isIn) {
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
} else {
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
// dispatch_async(dispatch_get_global_queue(0,0), ^{
// TableData *notice = [[TableData alloc] initWithJSONDictionary:self.dic];
// BOOL isIn = [[DBAction sharedDBAction] isInTable:notice];
// dispatch_async(dispatch_get_main_queue(), ^{
// if (isIn) {
// [btn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
// } else {
// [btn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
// }
//
// });
// });
}else{
[btn setImage:[[UIImage imageNamed:pics[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
}
[self addSubview:btn];
}
_line = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, Line_Height)];
_line.backgroundColor = Color_Line;
[self addSubview:_line];
}
- (void)clickedBtn:(UIButton *)btn{
self.block?self.block(btn.tag):@"";
}
@end