|
//
// notificationCell.m
// ThePaperHD
//
// Created by liyuan on 15/7/15.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "notificationCell.h"
@interface notificationCell()
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *title;
@property(nonatomic, strong)UIImageView *nextIcon;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)UILabel *markLabel;
@end
@implementation notificationCell
@synthesize topic = _topic;
@synthesize indexPath = _indexPath;
@synthesize msgDic = _msgDic;
- (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.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleGray;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.title];
[self.backView addSubview:self.nextIcon];
[self.backView addSubview:self.line];
[self.backView addSubview:self.markLabel];
}
return self;
}
#pragma mark -- view
-(UIView *)backView{
if (!_backView) {
_backView = [UIView new];
_backView.backgroundColor = [UIColor clearColor];
}
return _backView;
}
-(UILabel *)title{
if (!_title) {
_title = [[UILabel alloc] initWithFrame:CGRectZero];
_title.font = appFont(20, NO);
_title.textColor = [UIColor colorWithHexString:TextBlack];
_title.backgroundColor = [UIColor clearColor];
_title.userInteractionEnabled = NO;
}
return _title;
}
-(UIImageView *)nextIcon{
if (!_nextIcon) {
_nextIcon = [[UIImageView alloc] initWithFrame:CGRectZero];
_nextIcon.image = Image(@"setting/message_notificationcell_arrow.png");
}
return _nextIcon;
}
-(UIView *)line{
if (!_line) {
_line = [[UIView alloc] initWithFrame:CGRectZero];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (UILabel*)markLabel {
if (!_markLabel) {
_markLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"];
_markLabel.layer.cornerRadius = 11/2;
_markLabel.clipsToBounds = YES;
_markLabel.textAlignment = NSTextAlignmentCenter;
_markLabel.textColor = [UIColor whiteColor];
_markLabel.font = appFont(7, NO);
_markLabel.hidden = NO;
}
return _markLabel;
}
#pragma mark -- data
-(void)setTopic:(NSString *)str{
_topic = str;
self.title.text = _topic;
}
-(void)setIndexPath:(NSIndexPath *)index{
_indexPath = index;
}
-(void)setMsgDic:(NSMutableDictionary *)dic{
_msgDic = dic;
}
-(void)layoutSubviews{
[super layoutSubviews];
self.backView.frame = self.contentView.bounds;
self.title.frame = CGRectMake(15, 0, 120, CGRectGetHeight(self.contentView.bounds));
self.nextIcon.frame = CGRectMake(self.contentView.frame.size.width-24, CGRectGetHeight(self.contentView.bounds)/2 - 9/2, 9, 16);
self.line.frame = CGRectMake(15, CGRectGetHeight(self.contentView.bounds)-1, CGRectGetWidth(self.contentView.bounds)-30, 1);
if (_indexPath.section == 0) {
if(_indexPath.row == 0){
self.markLabel.layer.cornerRadius = 5;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+20, 10, 10, 10);
if ([_msgDic[@"questionMark"] intValue] >0) {
self.markLabel.hidden = NO;
}else{
self.markLabel.hidden = YES;
}
}else if (_indexPath.row == 1){
self.markLabel.layer.cornerRadius = 5;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+20, 10, 10, 10);
if ([_msgDic[@"attendMark"] intValue] >0) {
self.markLabel.hidden = NO;
}else{
self.markLabel.hidden = YES;
}
}else if (_indexPath.row == 2){
self.markLabel.layer.cornerRadius = 10;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+20, CGRectGetHeight(self.contentView.bounds)/2 - 10, 20, 20);
if ([_msgDic[@"replyedMark"] intValue] >0) {
self.markLabel.hidden = NO;
self.markLabel.font = appFont(10, NO);
if([_msgDic[@"replyedMark"] intValue] >9){
self.markLabel.text = @"9+";
}else{
self.markLabel.text = [NSString stringWithFormat:@"%@",_msgDic[@"replyedMark"]];
}
}else{
self.markLabel.hidden = YES;
}
self.line.frame = CGRectMake(0, CGRectGetHeight(self.contentView.bounds)-1, CGRectGetWidth(self.contentView.bounds), 1);
}else{
self.markLabel.hidden = NO;
self.line.frame = CGRectMake(0, CGRectGetHeight(self.contentView.bounds)-1, CGRectGetWidth(self.contentView.bounds), 1);
}
}else{
self.markLabel.hidden = YES;
// self.line.frame = CGRectMake(0, CGRectGetHeight(self.contentView.bounds)-1, CGRectGetWidth(self.contentView.bounds), 1);
}
}
@end
|