CNHomeRightHeaderFooterView.m 3.51 KB
//
//  CNHomeRightHeaderFooterView.m
//  CNLiveScioLive
//
//  Created by Xiaowen Zhang on 2018/9/19.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNHomeRightHeaderFooterView.h"
@interface CNHomeRightHeaderFooterView()
@property (nonatomic, strong) UIImageView *backgroundImage;
@property (nonatomic, strong) UIImageView *picImage;
@property (nonatomic, strong) UILabel *titleLabel;

@end
@implementation CNHomeRightHeaderFooterView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];

        _backgroundImage = [[UIImageView alloc] init];
        _backgroundImage.contentMode = UIViewContentModeCenter;
        _backgroundImage.layer.masksToBounds = YES;
        _backgroundImage.userInteractionEnabled = YES;
        _backgroundImage.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_backgroundImage];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.numberOfLines = 1;
        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        _titleLabel.textColor = HEXCOLOR(0x333333);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_titleLabel];
        
        _picImage = [[UIImageView alloc] init];
        _picImage.contentMode = UIViewContentModeCenter;
        _picImage.layer.masksToBounds = YES;
        _picImage.userInteractionEnabled = YES;
        [self.contentView addSubview:_picImage];
        
    }
    
    return self;
}
- (void)setTitle:(NSString *)title{
    _title = title;
    _titleLabel.text = title;
    
    if([title isEqualToString:@"搜索内容"]){
        _picImage.image = [UIImage imageNamed:@"cnlive_search"];
        
    }
    else if([title isEqualToString:@"栏目列表"]){
        _picImage.image = [UIImage imageNamed:@"cnlive_column"];
        
    }
    else{
        _picImage.image = [UIImage imageNamed:@"cnlive_scan"];

    }

}
- (void)layoutSubviews{
    
    [_backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(0);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.left.equalTo(self.mas_left).with.offset(0);
        make.right.equalTo(self.mas_right).with.offset(0);
    }];

    UIFont *font = [UIFont systemFontOfSize:16];
    CGSize size = CGSizeMake(MAXFLOAT, 30.0f);
    CGFloat titleWidth = [_title boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{ NSFontAttributeName:font } context:nil].size.width;
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset((self.width-titleWidth)/2.0);
        make.top.equalTo(self.mas_top).with.offset(0);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
    }];
    
    [_picImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(0);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.right.equalTo(self->_titleLabel.mas_left).with.offset(-10);
        make.width.offset(20);
    }];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


@end