|
//
// hotImageView.m
// ThePaperHD
//
// Created by YoungLee on 15/6/3.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "hotImageView.h"
#import "AsyncImageView.h"
@interface hotImageView(){
CGFloat textHeight;
}
@property(nonatomic, strong)AsyncImageView *img;
@property(nonatomic, strong)UILabel *title;
@property(nonatomic, strong)UIButton *clickBtn;
@property(nonatomic, strong)UIView *titleBg;
@end
@implementation hotImageView
@synthesize contentBo = _contentBo;
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self addSubview:self.img];
[self addSubview:self.titleBg];
[self.titleBg addSubview:self.title];
[self addSubview:self.clickBtn];
}
return self;
}
-(AsyncImageView *)img{
if (!_img) {
_img = [[AsyncImageView alloc] initWithFrame:CGRectZero];
}
return _img;
}
-(UIView *)titleBg{
if (!_titleBg) {
_titleBg = [[UIView alloc] initWithFrame:CGRectZero];
_titleBg.backgroundColor = [UIColor colorWithHexString:@"0x505050"];
}
return _titleBg;
}
-(UILabel *)title{
if (!_title) {
_title = [[UILabel alloc] initWithFrame:CGRectZero];
_title.numberOfLines = 0;
_title.lineBreakMode = NSLineBreakByWordWrapping;
_title.font = appFont(15, NO);
_title.textAlignment = NSTextAlignmentLeft;
_title.textColor = [UIColor whiteColor];
}
return _title;
}
-(UIButton *)clickBtn{
if (!_clickBtn) {
_clickBtn = [[UIButton alloc] initWithFrame:CGRectZero];
_clickBtn.backgroundColor = [UIColor clearColor];
[_clickBtn addTarget:self action:@selector(btnSelector:) forControlEvents:UIControlEventTouchUpInside];
}
return _clickBtn;
}
-(void) btnSelector:(UIButton *)btn{
if ([self.hotImgDelegate respondsToSelector:@selector(gotoImgVC:)]) {
[self.hotImgDelegate gotoImgVC:self.contentBo];
}
}
-(void)setContentBo:(listContObjectVO *)content{
_contentBo = content;
self.img.imageUrl = content.pic;
self.title.text = content.name;
}
-(void)layoutSubviews{
[super layoutSubviews];
self.clickBtn.frame = self.bounds;
// self.img.frame = self.bounds;
self.titleBg.frame = CGRectMake(0, CGRectGetHeight(self.bounds)-55, CGRectGetWidth(self.bounds), 55);
textHeight = heightForString(self.title.text, self.title.font, CGRectGetWidth(self.bounds)-20, self.title.lineBreakMode);
if (textHeight > 20) {
textHeight = 40;
}else{
textHeight=20;
}
self.title.frame = CGRectMake(10, 5, CGRectGetWidth(self.bounds)-20, textHeight);
self.img.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)-55);
}
@end
|