168 lines
5.4 KiB
Objective-C
168 lines
5.4 KiB
Objective-C
//
|
|
// CustomSystemTextCell.m
|
|
// XinjiangProject
|
|
//
|
|
// Created by Apple on 2024/6/14.
|
|
//
|
|
|
|
#import "CustomSystemTextCell.h"
|
|
|
|
@interface CustomSystemTextCell ()
|
|
|
|
@property (nonatomic, strong) UIImageView * heardImage;
|
|
|
|
@property (nonatomic, strong) UILabel * connetLabel;
|
|
|
|
@property (nonatomic, strong) UILabel * nickNameLabel;
|
|
|
|
@end
|
|
|
|
@implementation CustomSystemTextCell
|
|
|
|
- (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
|
|
}
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
{
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
if (self) {
|
|
|
|
[self createUI];
|
|
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)createUI {
|
|
|
|
self.heardImage = [[UIImageView alloc] init];
|
|
self.heardImage.backgroundColor = KWhiteColor;
|
|
self.heardImage.image = [UIImage imageNamed:@"heard_man"];
|
|
[self.contentView addSubview:self.heardImage];
|
|
self.heardImage.layer.cornerRadius = 20;
|
|
self.heardImage.layer.masksToBounds = true;
|
|
[self.heardImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(@15);
|
|
make.top.mas_equalTo(@8);
|
|
make.height.width.mas_equalTo(@30);
|
|
}];
|
|
|
|
self.nickNameLabel = [[UILabel alloc] init];
|
|
self.nickNameLabel.text = @"全科医生";
|
|
[self.contentView addSubview:self.nickNameLabel];
|
|
self.nickNameLabel.font = SYSTEMFONT(12);
|
|
[self.nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.heardImage.mas_right).offset(10);
|
|
make.top.mas_equalTo(@10);
|
|
make.width.mas_equalTo(@300.0);
|
|
make.height.mas_offset(13);
|
|
}];
|
|
|
|
|
|
self.connetLabel = [[UILabel alloc] init];
|
|
self.connetLabel.backgroundColor = KWhiteColor;
|
|
[self.contentView addSubview:self.connetLabel];
|
|
self.connetLabel.font = SYSTEMFONT(15);
|
|
self.connetLabel.layer.cornerRadius = 10;
|
|
self.connetLabel.layer.masksToBounds = true;
|
|
self.connetLabel.numberOfLines = 0;
|
|
[self.connetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.heardImage.mas_right).offset(8);
|
|
make.top.mas_equalTo(self.nickNameLabel.mas_bottom).offset(2);
|
|
make.width.mas_equalTo(@300.0);
|
|
make.bottom.mas_offset(8);
|
|
}];
|
|
[self.connetLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_offset(0);
|
|
make.bottom.mas_equalTo(self.connetLabel.mas_bottom).offset(10);
|
|
}];
|
|
}
|
|
|
|
- (void)setModel:(CustomTUIHistoryModel *)model {
|
|
|
|
_model = model;
|
|
|
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
paragraphStyle.firstLineHeadIndent = 10.0; // 左边距
|
|
paragraphStyle.headIndent = 10.0; // 左边距
|
|
paragraphStyle.tailIndent = -10.0; // 右边距
|
|
|
|
NSDictionary *attributes = @{
|
|
NSParagraphStyleAttributeName: paragraphStyle
|
|
};
|
|
|
|
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:model.content attributes:attributes];
|
|
|
|
// 将带有内边距的 attributedText 赋值给 UILabel
|
|
self.connetLabel.attributedText = attributedText;
|
|
|
|
if (_model.isSelf == true) { //头像在右
|
|
|
|
[self.heardImage mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(@-15);
|
|
make.top.mas_equalTo(@8);
|
|
make.height.width.mas_equalTo(@30);
|
|
}];
|
|
|
|
[self.connetLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.right.mas_equalTo(self.heardImage.mas_left).offset(10);
|
|
make.top.mas_equalTo(@10);
|
|
make.width.mas_equalTo(@300.0);
|
|
make.bottom.mas_offset(8);
|
|
}];
|
|
[self.connetLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
|
}else
|
|
{
|
|
[self.heardImage mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(@15);
|
|
make.top.mas_equalTo(@8);
|
|
make.height.width.mas_equalTo(@40);
|
|
}];
|
|
|
|
[self.nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.heardImage.mas_right).offset(10);
|
|
make.top.mas_equalTo(@10);
|
|
make.width.mas_equalTo(@300.0);
|
|
make.height.mas_offset(13);
|
|
}];
|
|
|
|
|
|
[self.connetLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.heardImage.mas_right).offset(10);
|
|
make.top.mas_equalTo(self.nickNameLabel.mas_bottom).offset(5);
|
|
make.width.mas_equalTo(@245.0);
|
|
make.bottom.mas_offset(8);
|
|
}];
|
|
}
|
|
[self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_offset(0);
|
|
make.bottom.mas_equalTo(self.connetLabel.mas_bottom).offset(10);
|
|
}];
|
|
[self.contentView layoutIfNeeded];
|
|
|
|
// [self.heardImage sd_setImageWithURL: [NSURL URLWithString: [NSString stringWithFormat:@"%@",_model.avatar]] placeholderImage:PLACEHOLD_IMG];
|
|
|
|
}
|
|
|
|
|
|
@end
|