|
//
// 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)UILabel *title;
@property(nonatomic, strong)UIImageView *nextIcon;
@property(nonatomic, strong)UIView *line;
@property(nonatomic ,strong)UIView *backView;
@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];
if (selected) {
self.markLabel.hidden = YES;
}
// Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
// [self.contentView addSubview:self.backView];
[self addSubview:self.backView];
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, rect_screen.size.width-20 , 49)];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
[self.backView addSubview:self.title];
[self.backView addSubview:self.nextIcon];
[self.backView addSubview:self.line];
[self.backView addSubview:self.markLabel];
[self layoutSub];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.title.textColor = [UIColor colorWithHexString:TextBlack];
self.line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
self.markLabel.backgroundColor = [UIColor colorWithHexString:@"0xc32128"];
self.markLabel.textColor = [UIColor whiteColor];
//夜间模式:我的消息页,如此操作有反色异常(bug:6158)
self.selectedBackgroundView = nil;
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, rect_screen.size.width-20 , 49)];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
}
#pragma mark -- view
-(UIView *)backView{
if (!_backView) {
_backView = [[UIView alloc] initWithFrame:CGRectZero];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
-(UILabel *)title{
if (!_title) {
_title = [[UILabel alloc] initWithFrame:CGRectZero];
_title.font = appFont(16, 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 = YES;
}
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;
if (_indexPath.section == 0) {
if(_indexPath.row == 0){
if ([_msgDic[@"questionMark"] intValue] >0) {
self.markLabel.hidden = NO;
self.markLabel.layer.cornerRadius = 5;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+15, 10, 10, 10);
}else{
self.markLabel.hidden = YES;
}
}else if (_indexPath.row == 1){
if ([_msgDic[@"attendMark"] intValue] >0) {
self.markLabel.hidden = NO;
self.markLabel.layer.cornerRadius = 5;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+15, 10, 10, 10);
}else{
self.markLabel.hidden = YES;
}
}else if (_indexPath.row == 2){
if ([_msgDic[@"replyedMark"] intValue] >0) {
self.markLabel.hidden = NO;
self.markLabel.layer.cornerRadius = 15/2;
self.markLabel.frame = CGRectMake(widthForString(self.title.text, self.title.font, CGRectGetHeight(self.contentView.bounds), self.title.lineBreakMode)+20, CGRectGetHeight(self.contentView.bounds)/2 - 15/2, 15, 15);
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;
}
}
}else{
self.markLabel.hidden = YES;
}
}
-(void)layoutSub{
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.right.equalTo(self.right).offset(-10);
make.top.equalTo(self.top);
make.height.equalTo(@50);
}];
[self.title makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.width.mas_equalTo(200);
make.top.equalTo(self.backView.top);
make.bottom.equalTo(self.backView.bottom);
}];
[self.nextIcon makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.right).offset(-24);
make.width.mas_equalTo(9);
make.centerY.equalTo(self.backView.centerY);
make.height.mas_equalTo(16);
}];
[self.line makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.bottom).offset(-1);
make.bottom.equalTo(self.backView.bottom);
}];
}
@end
|