|
//
// topicDescCell.m
// ThePaperHD
//
// Created by scar1900 on 15/5/12.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicDescCell.h"
#define tableWidht 1230/2
@interface topicDescCell() {
CGFloat descHeight;
}
@property(nonatomic, strong)UILabel *descLabel;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)UIButton *expandBtn;
@end
@implementation topicDescCell
@synthesize topicDesc = _topicDesc;
@synthesize padding;
@synthesize expand;
@synthesize delegate;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self.contentView addSubview:self.descLabel];
[self.contentView addSubview:self.expandBtn];
[self.contentView addSubview:self.line];
self.expand = NO;
}
return self;
}
- (void)setTopicDesc:(NSString *)str {
_topicDesc = str;
descHeight = heightForString(str, appFont(14, NO), tableWidht, NSLineBreakByWordWrapping)+15;
if (descHeight > 83) {
if (!self.expand) {
descHeight = 83;
}
self.expandBtn.hidden = NO;
}else {
self.expandBtn.hidden = YES;
}
self.descLabel.text = str;
}
- (UILabel*)descLabel {
if (!_descLabel) {
_descLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_descLabel.font = appFont(14, NO);
_descLabel.textColor = [UIColor colorWithHexString:TextGray];
_descLabel.textAlignment = NSTextAlignmentLeft;
_descLabel.lineBreakMode = NSLineBreakByWordWrapping;
_descLabel.numberOfLines = 0;
_descLabel.backgroundColor = [UIColor clearColor];
}
return _descLabel;
}
- (UIButton*)expandBtn {
if (!_expandBtn) {
_expandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_expandBtn.backgroundColor = [UIColor clearColor];
_expandBtn.hidden = YES;
[_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
[_expandBtn addTarget:self action:@selector(expandEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _expandBtn;
}
- (UIView*)line {
if (!_line) {
_line = [[UIView alloc]initWithFrame:CGRectZero];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (void)expandEvent:(UIButton*)btn {
self.expand = !self.expand;
if ([self.delegate respondsToSelector:@selector(clickToExpand:)]) {
[self.delegate clickToExpand:self.expand];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
self.descLabel.frame = CGRectMake(self.padding, 13, tableWidht, descHeight);
if (!self.expand) {
[_expandBtn setImage:Image(@"detailPage/expandArrow.png") forState:UIControlStateNormal];
}else {
[_expandBtn setImage:Image(@"detailPage/expandArrowUp.png") forState:UIControlStateNormal];
}
self.expandBtn.frame = CGRectMake(padding,
CGRectGetMaxY(self.descLabel.frame),
tableWidht,
30);
[self.expandBtn setImageEdgeInsets:UIEdgeInsetsMake(15-15/2,
CGRectGetWidth(self.expandBtn.frame)/2-13,
15-15/2,
CGRectGetWidth(self.expandBtn.frame)/2-13)];
self.line.frame = CGRectMake(padding, CGRectGetHeight(self.contentView.bounds)-1, tableWidht, 1);
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|