admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
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
//
//  commetHeaderView.m
//  mgysVideo
//
//  Created by weikou on 16/7/25.
//  Copyright © 2016年 wgj. All rights reserved.
//
 
#import "commentHeaderView.h"
 
@implementation commentHeaderView
 
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithReuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor=kGlobalBackgroundColor;
        //分割线
        UILabel *Splitline=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 0.5)];
        Splitline.backgroundColor=KGlobalLightGreyColor_230;
        [self.contentView addSubview:Splitline];
        _Splitline=Splitline;
        
        //创建回复评论用户的头像视图
        UIImageView *headImage=[[UIImageView alloc] init];
        headImage.frame=CGRectMake(5, 15, 40, 40);
        
        //设置成圆形头像
        headImage.layer.masksToBounds=YES;
        headImage.layer.cornerRadius=20;
        [self.contentView addSubview:headImage];
        _headerImageView=headImage;
        
        //创建回复评论用户的用户名
        UILabel *username=[[UILabel alloc] init];
        username.frame=CGRectMake(50, 20, KScreenW/2, 10);
        username.font=[UIFont systemFontOfSize:14];
        [self.contentView addSubview:username];
        _userNameLabel=username;
        
        //显示用户回复的时间
        UILabel *commentTime=[[UILabel alloc] init];
        commentTime.frame=CGRectMake(50, 35, KScreenW/2, 20);
        commentTime.font=[UIFont systemFontOfSize:12];
        [self.contentView addSubview:commentTime];
        _commentTimeLabel=commentTime;
        
        //用户的评论
        UILabel *commentContentView=[[UILabel alloc] init];
        commentContentView.frame=CGRectMake(50, 55, KScreenW-70, 0);
        commentContentView.font=[UIFont systemFontOfSize:14];
        commentContentView.numberOfLines=0;
        commentContentView.lineBreakMode=NSLineBreakByTruncatingTail;
        [self.contentView addSubview:commentContentView];
        _commentContentLabel=commentContentView;
        
        //举报功能
        UIButton *ReportBtn=[[UIButton alloc] init];
        ReportBtn.backgroundColor=[UIColor clearColor];
        ReportBtn.frame=CGRectMake(KScreenW-115, 20, 50, 20);
        [ReportBtn setTitle:@"举报" forState:UIControlStateNormal];
        [ReportBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        ReportBtn.titleLabel.font=[UIFont systemFontOfSize:14];
        [ReportBtn addTarget:self action:@selector(ReportMessage) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:ReportBtn];
        _ReportButton=ReportBtn;
        
        //设置点击回复的Button
        UIButton *replyBtn=[[UIButton alloc] init];
        replyBtn.backgroundColor=[UIColor clearColor];
        replyBtn.frame=CGRectMake(KScreenW-75, 10, 50, 30);
        [replyBtn setTitle:@"回复" forState:UIControlStateNormal];
        [replyBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        replyBtn.titleLabel.font=[UIFont systemFontOfSize:14];
        
        [replyBtn addTarget:self action:@selector(replyMessage) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:replyBtn];
        _replyButton=replyBtn;
    }
    return self;
}
 
-(void)replyMessage{
    NSLog(@"点击了回复,%d",[_section intValue]);
    //添加 字典,将label的值通过key值设置传递
    NSString *str=[NSString stringWithFormat:@"%d",[_section intValue]];
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setObject:str forKey:@"replyMessage"];
    [dict setObject:@"回复" forKey:@"replyType"];
    //创建通知
    NSNotification *notification =[NSNotification notificationWithName:@"reply" object:nil userInfo:dict];
    //通过通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
 
-(void)ReportMessage{
    NSLog(@"点击了回复,%d",[_section intValue]);
    //添加 字典,将label的值通过key值设置传递
    NSString *str=[NSString stringWithFormat:@"%d",[_section intValue]];
    NSMutableDictionary *dict =[NSMutableDictionary dictionary];
    [dict setObject:str forKey:@"replyMessage"];
    [dict setObject:@"举报" forKey:@"replyType"];
    //创建通知
    NSNotification *notification =[NSNotification notificationWithName:@"reply" object:nil userInfo:dict];
    //通过通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:notification];
 
}
 
+(instancetype)headerViewWithTableView:(UITableView*)tableView{
    static NSString *sectionID=@"Header";
    commentHeaderView *headerView=[tableView dequeueReusableHeaderFooterViewWithIdentifier:sectionID];
    if (headerView==nil) {
        headerView=[[commentHeaderView alloc] initWithReuseIdentifier:sectionID];
    }
    return headerView;
}
 
@end