|
//
// columnHeaderView.m
// ThePaperDemo
//
// Created by scar1900 on 14/10/31.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "columnHeaderView.h"
#import "AsyncImageView.h"
#define bottomLineTag 1002
@interface columnHeaderView() {
CGFloat originHeight;
CGFloat minHeight;
}
@property(nonatomic, strong)AsyncImageView *imageView;
@property(nonatomic, strong)AsyncImageView *sponsorImageView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *descLabel;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UIView *sepLineView;
@end
@implementation columnHeaderView
@synthesize spansorData = _spansorData;
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame withNodeObject:(nodeObjectBO*)obj{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self addSubview:self.imageView];
[self addSubview:self.titleLabel];
if (obj.sponsor) {
sponsorBO *sponsor = setJsonDicToDataModel(obj.sponsor, [sponsorBO class]);
self.spansorData = sponsor;
}
[self addSubview:self.lineView];
[self addSubview:self.descLabel];
self.imageView.imageUrl = obj.pic;
self.imageView.imageId = getImageNameFromURL(obj.pic);
self.titleLabel.text = obj.name;
self.descLabel.text = obj.desc;
originHeight = frame.size.height;
if (isIOS7) {
minHeight = 63;
}else minHeight = 45;
UIView *bottomLine = [[UIView alloc]initWithFrame:CGRectMake(0,
CGRectGetHeight(self.bounds)-1,
CGRectGetWidth(self.bounds),
1)];
bottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
bottomLine.tag = bottomLineTag;
[self addSubview:bottomLine];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sponsorTap:)];
[self.sponsorImageView addGestureRecognizer:tap];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)setSpansorData:(sponsorBO *)data {
_spansorData = data;
CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(0, 0)];
CGFloat titleWidth = size.width;
[UIView animateWithDuration:0.35 animations:^{
self.titleLabel.frame = CGRectMake(CGRectGetWidth(self.bounds)/2+10, CGRectGetHeight(self.bounds)-60, titleWidth, 30);
[self addSubview:self.sponsorImageView];
self.sponsorImageView.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-10-120,
CGRectGetMinY(self.titleLabel.frame),
120,
30);
self.sponsorImageView.hidden = NO;
}completion:^(BOOL finished) {
self.sponsorImageView.imageUrl = data.logo;
self.sponsorImageView.imageId = getImageNameFromURL(data.logo);
}];
}
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
// NSLog(@"%f",frame.origin.y);
CGFloat offset = (originHeight-minHeight + frame.origin.y)/(originHeight-minHeight);
if (offset >= 0) {
CGFloat alpha = (originHeight-2*minHeight + frame.origin.y)/(originHeight-2*minHeight);
self.descLabel.alpha = alpha;
self.lineView.alpha = self.descLabel.alpha;
self.imageView.alpha = offset;
CGFloat titleFontSize = 17+offset*(20-17);
self.titleLabel.font = appFont(titleFontSize, NO);
CGFloat titleBottomPadding = 30+offset*(60-30);
CGFloat titleHeight = 20+offset*(30-20);
CGFloat sponserWidth = 80+offset*(120-80);
CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(0, 0)];
CGFloat titleWidth = size.width;
if (!self.sponsorImageView.hidden) {
self.titleLabel.frame = CGRectMake(CGRectGetWidth(self.bounds)/2+10,
CGRectGetMaxY(self.bounds)-titleBottomPadding,
titleWidth,
titleHeight);
self.sponsorImageView.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-10-sponserWidth,
CGRectGetMinY(self.titleLabel.frame),
sponserWidth,
titleHeight);
}else {
self.titleLabel.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-titleWidth/2,
CGRectGetMaxY(self.bounds)-titleBottomPadding,
titleWidth,
titleHeight);
}
}
}
- (AsyncImageView*)sponsorImageView {
if (!_sponsorImageView) {
_sponsorImageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-10-60,
CGRectGetMinY(self.titleLabel.frame),
120,
30)];
_sponsorImageView.hidden = YES;
_sponsorImageView.userInteractionEnabled = YES;
}
_sponsorImageView.isHaveWaterPrint = NO;
return _sponsorImageView;
}
- (AsyncImageView*)imageView {
if (!_imageView) {
CGFloat imgY = 25;
if (isIOS7) {
imgY = imgY + 18;
}
_imageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-35/2, imgY, 35, 35)];
_imageView.backgroundColor = [UIColor clearColor];
_imageView.isHaveWaterPrint = NO;
_imageView.imageView.backgroundColor = [UIColor clearColor];
}
return _imageView;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-50, CGRectGetHeight(self.bounds)-60, 100, 30)];
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = appFont(TEXT_ONE_PLUS_LEVELSIZE, NO);
}
return _titleLabel;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-100, CGRectGetMaxY(self.titleLabel.frame)+ 5, 200, 1)];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (void)sponsorTap:(UIGestureRecognizer*)tap {
if ([self.delegate respondsToSelector:@selector(GotoSponsorAd:)]) {
[self.delegate GotoSponsorAd:self.spansorData];
}
}
- (UIView*)sepLineView {
if (!_sepLineView) {
}
return _sepLineView;
}
- (UILabel*)descLabel {
if (!_descLabel) {
_descLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lineView.frame)+5, CGRectGetWidth(self.bounds), 25/2)];
_descLabel.textColor = [UIColor colorWithHexString:LINECOLOR];
_descLabel.textAlignment = NSTextAlignmentCenter;
_descLabel.backgroundColor = [UIColor clearColor];
}
_descLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
return _descLabel;
}
- (void)goToAd:(UIButton*)btn {
}
- (void)layoutSubviews {
[super layoutSubviews];
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
UIView *bottomLine = [self viewWithTag:bottomLineTag];
bottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
self.titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
self.descLabel.textColor = [UIColor colorWithHexString:LINECOLOR];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
|