|
//
// topicSearchCell.m
// ThePaperHD
//
// Created by YoungLee on 15/6/8.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicSearchCell.h"
@interface topicSearchCell(){
CGFloat contentHeight;
}
@property(nonatomic, strong)RTLabel *content;
@property(nonatomic, strong)UILabel *type;
@property(nonatomic, strong)RTLabel *name;
@property(nonatomic, strong)UILabel *time;
@property(nonatomic, strong)UIView *line;
@end
@implementation topicSearchCell
@synthesize topicInfo = _topicInfo;
- (void)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.selectionStyle = UITableViewCellSelectionStyleGray;
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.contentView addSubview:self.content];
[self.contentView addSubview:self.type];
[self.contentView addSubview:self.name];
[self.contentView addSubview:self.time];
[self.contentView addSubview:self.line];
}
return self;
}
-(void)setData:(TopicInfoBO *)topic key:(NSString *)key{
_topicInfo = topic;
contentHeight = returnTextHeightWithRTLabel(_topicInfo.title, searchPopSize.width-30, self.content.font, 8);
// contentHeight = heightForString(_topicInfo.title, appFont(17, NO), searchPopSize.width-30, self.content.lineBreakMode);
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
NSString *contentStr = _topicInfo.title;
if ([contentStr isMatchedByRegex:key]){
contentStr = [contentStr stringByReplacingOccurrencesOfString:key withString:[NSString stringWithFormat:@"<font color='#00a5eb'>%@</font><N>",key]];
}
self.content.text = contentStr;
self.type.text = topic.categoryName;
NSString *nameStr = user.sname;
if ([nameStr isMatchedByRegex:key]){
nameStr = [nameStr stringByReplacingOccurrencesOfString:key withString:[NSString stringWithFormat:@"<font color='#00a5eb'>%@</font><N>",key]];
}
self.name.text = nameStr;
self.time.text = topic.publishTime;
}
-(RTLabel *)content{
if (!_content) {
_content = [[RTLabel alloc] initWithFrame:CGRectZero];
_content.font = appFont(17, NO);
_content.backgroundColor = [UIColor clearColor];
_content.textColor = [UIColor colorWithHexString:TextBlack];
// _content.numberOfLines = 0;
_content.lineBreakMode = RTTextLineBreakModeWordWrapping;
_content.lineSpacing = 8;
// _content.lineBreakMode = NSLineBreakByWordWrapping;
}
return _content;
}
-(UILabel *)type{
if (!_type) {
_type = [[UILabel alloc] initWithFrame:CGRectZero];
_type.font = appFont(9, NO);
_type.backgroundColor = [UIColor clearColor];
_type.textColor = [UIColor colorWithHexString:TextGray];
}
return _type;
}
-(RTLabel *)name{
if (!_name) {
_name = [[RTLabel alloc] initWithFrame:CGRectZero];
_name.font = appFont(9, NO);
_name.lineSpacing = 8;
_name.lineBreakMode = RTTextLineBreakModeWordWrapping;
_name.backgroundColor = [UIColor clearColor];
_name.textColor = [UIColor colorWithHexString:TextGray];
}
return _name;
}
-(UILabel *)time{
if (!_time) {
_time = [[UILabel alloc] initWithFrame:CGRectZero];
_time.font = appFont(9, NO);
_time.backgroundColor = [UIColor clearColor];
_time.textColor = [UIColor colorWithHexString:TextGray];
}
return _time;
}
-(UIView *)line{
if (!_line) {
_line = [[UIView alloc] initWithFrame:CGRectZero];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
-(void)layoutSubviews{
[super layoutSubviews];
self.content.frame = CGRectMake(15, 5, searchPopSize.width-30, contentHeight+5);
self.type.frame = CGRectMake(CGRectGetMinX(self.content.frame), CGRectGetMaxY(self.content.frame)+5, widthForString(self.type.text, appFont(9, NO), 20, self.type.lineBreakMode), 20);
CGFloat width = returnTextWidthWithRTLabel(self.name.text, 20, self.name.font,8);
CGFloat height = returnTextHeightWithRTLabel(self.name.text, width, self.name.font, 8);
self.name.frame = CGRectMake(CGRectGetMaxX(self.type.frame)+10, CGRectGetMinY(self.type.frame)+10-height/2, width,height );
self.time.frame = CGRectMake(CGRectGetMaxX(self.name.frame)+10, CGRectGetMinY(self.type.frame), widthForString(self.time.text, appFont(9, NO), 20, self.time.lineBreakMode), 20);
self.line.frame = CGRectMake(CGRectGetMinX(self.content.frame), CGRectGetMaxY(self.contentView.bounds)-1, searchPopSize.width-30, 1);
}
@end
|