123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- //
- // KSSearchResultViewCell.m
- // TeacherDaya
- //
- // Created by Kyle on 2020/10/27.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "KSSearchResultViewCell.h"
- #import "KSSearchResultModel.h"
- #import "KSSearchRCLabel.h"
- @interface KSSearchResultViewCell ()
- @property (nonatomic, strong) UILabel *otherLabel;
- @property (nonatomic, strong) UILabel *timeLabel;
- @end
- @implementation KSSearchResultViewCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.backgroundColor = HexRGBAlpha(0xffffff, 0.4);
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- [self loadView];
- }
- return self;
- }
- - (void)setDataModel:(KSSearchResultModel *)model {
- float namelLabelWidth = kScreenWidth - 20 - 48 - 9.5;
- if (model.time) {
- self.timeLabel.hidden = NO;
- namelLabelWidth -= 100;
- } else {
- self.timeLabel.hidden = YES;
- }
- if (!(model.otherInformation.length > 0) || !(model.name.length > 0)) {
- self.nameLabel.frame =
- CGRectMake(CGRectGetMaxX(self.headerView.frame) + 9.5, (65 - 17) / 2, namelLabelWidth, 17);
- self.additionalLabel.hidden = YES;
- self.otherLabel.hidden = YES;
- NSString *str = nil;
- if (model.otherInformation.length > 0) {
- str = model.otherInformation;
- } else {
- str = model.name;
- }
- [self.nameLabel attributedText:str byHighlightedText:self.searchString];
- } else {
- self.nameLabel.frame = CGRectMake(CGRectGetMaxX(self.headerView.frame) + 9.5,
- CGRectGetMinY(self.headerView.frame) + 3, namelLabelWidth, 17);
- self.additionalLabel.hidden = NO;
- self.otherLabel.hidden = NO;
- CGFloat height = CGRectGetMaxY(self.headerView.frame) - 20;
- CGFloat width = CGRectGetMaxX(self.headerView.frame) + 9.5;
- CGFloat additionalLabelWidth = kScreenWidth - 20 - 48 - 9.5;
-
- if ([model.objectName isEqualToString:@"RC:FileMsg"]) {
- self.otherLabel.text = @"[文件]";
- } else if ([model.objectName isEqualToString:@"RC:ImgTextMsg"]) {
- self.otherLabel.text = @"[链接]";
- } else {
- self.otherLabel.text = @"";
- self.otherLabel.frame = CGRectZero;
- CGRect rect = self.additionalLabel.frame;
- rect.origin.x = width;
- rect.size.width = additionalLabelWidth;
- self.additionalLabel.frame = rect;
- }
- self.otherLabel.frame = CGRectMake(width, height, 40, 16);
- [self.otherLabel sizeToFit];
- self.additionalLabel.frame = CGRectMake(width + self.otherLabel.frame.size.width, height,
- additionalLabelWidth - CGRectGetWidth(self.otherLabel.frame), 16);
- if (model.time) {
- self.timeLabel.text = [RCKitUtility convertConversationTime:model.time / 1000];
- }
- self.nameLabel.text = model.name;
- if (model.count > 1) {
- self.additionalLabel.text = model.otherInformation;
- } else {
- [self.additionalLabel attributedText:model.otherInformation byHighlightedText:self.searchString];
- }
-
- }
- if (!(model.portraitUri.length > 0)) {
- if (model.conversationType == ConversationType_GROUP) {
- self.headerView.image = [self imageNamed:@"default_group_portrait" ofBundle:@"RongCloud.bundle"];
- }
- else {
- self.headerView.image = [self imageNamed:@"default_portrait_msg" ofBundle:@"RongCloud.bundle"];
- }
-
- } else {
- if (model.conversationType == ConversationType_GROUP) {
- [self.headerView
- sd_setImageWithURL:[NSURL URLWithString:[model.portraitUri getUrlEndcodeString]]
- placeholderImage:[self imageNamed:@"default_group_portrait" ofBundle:@"RongCloud.bundle"]];
- }
- else {
- [self.headerView
- sd_setImageWithURL:[NSURL URLWithString:[model.portraitUri getUrlEndcodeString]]
- placeholderImage:[self imageNamed:@"default_portrait_msg" ofBundle:@"RongCloud.bundle"]];
- }
-
- }
- }
- - (void)loadView {
- self.headerView = [[UIImageView alloc] initWithFrame:CGRectMake(10, (65 - 48) / 2, 48, 48)];
- self.headerView.layer.cornerRadius = 24;
- self.headerView.layer.masksToBounds = YES;
- [self.contentView addSubview:self.headerView];
- self.nameLabel = [[KSSearchRCLabel alloc] initWithFrame:CGRectZero];
- self.nameLabel.font = [UIFont systemFontOfSize:15.f];
- self.nameLabel.textColor = HexRGB(0x000000);
- [self.contentView addSubview:self.nameLabel];
- self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width - 100 - 10, (65 - 48) / 2, 100, 17)];
- self.timeLabel.textColor = HexRGB(0x999999);
- self.timeLabel.font = [UIFont systemFontOfSize:15.f];
- self.timeLabel.textAlignment = NSTextAlignmentRight;
- [self.contentView addSubview:self.timeLabel];
- self.otherLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- self.otherLabel.textColor = HexRGB(0x999999);
- self.otherLabel.font = [UIFont systemFontOfSize:14.f];
- self.additionalLabel = [[KSSearchRCLabel alloc] initWithFrame:CGRectZero];
- self.additionalLabel.font = [UIFont systemFontOfSize:14.f];
- self.additionalLabel.textColor = HexRGB(0x999999);
-
- [self.contentView addSubview:self.otherLabel];
- [self.contentView addSubview:self.additionalLabel];
- }
- - (UIImage *)imageNamed:(NSString *)name ofBundle:(NSString *)bundleName {
- UIImage *image = nil;
- NSString *image_name = [NSString stringWithFormat:@"%@.png", name];
- NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
- NSString *bundlePath = [resourcePath stringByAppendingPathComponent:bundleName];
- NSString *image_path = [bundlePath stringByAppendingPathComponent:image_name];
- image = [[UIImage alloc] initWithContentsOfFile:image_path];
- return image;
- }
- @end
|