//
|
// PBCommentsCell.m
|
// IphoneBIMe
|
//
|
// Created by ZJF on 2020/3/18.
|
// Copyright © 2020 ProBIM. All rights reserved.
|
//
|
|
#import "PBCommentsCell.h"
|
#import "PBProjectModel.h"
|
#import "PBCommentsModel.h"
|
@interface PBCommentsCell()
|
@property (nonatomic, weak) UIImageView *iconImageV;
|
@property (nonatomic, weak) UILabel *creatorL;
|
@property (nonatomic, weak) UILabel *textL;
|
@property (nonatomic, weak) UILabel *creatimeL;
|
@property (nonatomic, weak) UIButton *deleteBtn;
|
@property (nonatomic, weak) UILabel *iconL;
|
@end
|
@implementation PBCommentsCell
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)setupUI {
|
UIImageView *iconImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Issue_comments_iconbg"]];
|
[self.contentView addSubview:iconImageV];
|
[iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(8);
|
make.left.equalTo(self.contentView).offset(16);
|
make.size.mas_equalTo(CGSizeMake(30, 30));
|
}];
|
UILabel *iconL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:YES Font:DescFontSize];
|
iconL.textAlignment = NSTextAlignmentCenter;
|
[iconImageV addSubview:iconL];
|
[iconL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.right.equalTo(iconImageV);
|
make.height.equalTo(@20);
|
make.center.equalTo(iconImageV);
|
}];
|
UILabel *creatorL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:YES Font:TitleFontSize];
|
[self.contentView addSubview:creatorL];
|
[creatorL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(8);
|
make.left.equalTo(iconImageV.mas_right).offset(8);
|
make.height.equalTo(@22);
|
make.right.equalTo(self.contentView).offset(-16);
|
}];
|
UILabel *textL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:CommentsSize];
|
textL.numberOfLines = 0;
|
[self.contentView addSubview:textL];
|
[textL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(creatorL.mas_bottom).offset(8);
|
make.left.equalTo(self.contentView).offset(54);
|
make.right.equalTo(self.contentView).offset(-16);
|
}];
|
UILabel *creatimeL = [UILabel z_labelWithText:@"" Color:PromptColor isBold:NO Font:DescFontSize];
|
[self.contentView addSubview:creatimeL];
|
[creatimeL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(textL.mas_bottom).offset(12);
|
make.bottom.equalTo(self.contentView).offset(-18);
|
make.left.equalTo(self.contentView).offset(54);
|
make.height.equalTo(@20);
|
}];
|
UIButton *deleteBtn = [[UIButton alloc] init];
|
[deleteBtn setImage:[UIImage imageNamed:@"Issue_comment_deleteBtn"] forState:UIControlStateNormal];
|
[deleteBtn addTarget:self action:@selector(deletecomment) forControlEvents:UIControlEventTouchUpInside];
|
[self.contentView addSubview:deleteBtn];
|
[deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(creatimeL);
|
make.right.equalTo(self.contentView).offset(-16);
|
make.size.mas_equalTo(CGSizeMake(20, 20));
|
}];
|
UIView *linV = [[UIView alloc] init];
|
linV.backgroundColor = PBColor(242, 242, 242);
|
[self.contentView addSubview:linV];
|
[linV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.bottom.left.right.equalTo(self.contentView);
|
make.height.equalTo(@10);
|
}];
|
self.iconImageV = iconImageV;
|
self.creatorL = creatorL;
|
self.textL = textL;
|
self.creatimeL = creatimeL;
|
self.deleteBtn = deleteBtn;
|
self.iconL = iconL;
|
}
|
//删除
|
- (void)deletecomment {
|
if (self.deleteCommentsBlock) {
|
self.deleteCommentsBlock();
|
}
|
}
|
- (void)setCommentsModel:(PBCommentsModel *)commentsModel {
|
_commentsModel = commentsModel;
|
|
if (commentsModel.realname == nil || [commentsModel.realname isEqualToString:@""]) {
|
self.iconL.text = @"";
|
}else {
|
BOOL isChiness = [self IsChinese:commentsModel.realname];
|
if (isChiness) {
|
self.iconL.text = [commentsModel.realname substringFromIndex:commentsModel.realname.length - 1];
|
}else {
|
self.iconL.text = [commentsModel.realname substringToIndex:1];
|
}
|
}
|
// self.iconL.text = commentsModel.realname;
|
self.creatorL.text = commentsModel.realname;
|
if ([commentsModel.userid isEqualToString:UserID]) {
|
self.deleteBtn.hidden = NO;
|
}else {
|
self.deleteBtn.hidden = YES;
|
}
|
self.textL.text = commentsModel.content;
|
NSRange range = [commentsModel.createdate rangeOfString:@":"];
|
NSString *timeStr = [commentsModel.createdate substringToIndex:range.location + 3];
|
timeStr = [timeStr stringByReplacingOccurrencesOfString:@"T" withString:@" "];
|
self.creatimeL.text = [timeStr stringByReplacingOccurrencesOfString:@"-" withString:@"/"];
|
}
|
- (BOOL)IsChinese:(NSString *)str {
|
for(int i=0; i< [str length];i++){
|
int a = [str characterAtIndex:i];
|
if( a > 0x4e00 && a < 0x9fff){
|
return YES;
|
}
|
}
|
return NO;
|
}
|
- (void)awakeFromNib {
|
[super awakeFromNib];
|
// Initialization code
|
}
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
[super setSelected:selected animated:animated];
|
|
// Configure the view for the selected state
|
}
|
|
@end
|