headerview.h
@property(nonatomic,strong) UIImageView * imageView;
@property(nonatomic,strong) UILabel * label1;
@property(nonatomic,strong) UIImageView * imageView2;
@property(nonatomic,strong) UILabel * label2;
@property(nonatomic,strong) UILabel * label3;
@property(nonatomic,strong) UILabel * label4;
-(void)setValueForHeaderView:(NSDictionary *)dic;
.m
#import "HeaderView.h"
@implementation HeaderView
-(instancetype)initWithFrame:(CGRect)frame{
if ([super initWithFrame:frame]) {
[self addView];
}
return self;
}
-(void)setValueForHeaderView:(NSDictionary *)dic{
NSLog(@"_____________________________________________-%@",dic);
self.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:dic[@"coverOrigin"]]]];
self.imageView2.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:dic[@"avatarPath"]]]];
self.label1.text = dic[@"customTitle"];
self.label2.text = dic[@"shortIntro"];
NSString * timeStampString = [NSString stringWithFormat:@"%@",dic[@"lastUptrackAt"]];
NSTimeInterval interval = [timeStampString doubleValue] /1000.0;
NSDate * date = [NSDate dateWithTimeIntervalSince1970:interval];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd "];
self.label3.text = [NSString stringWithFormat:@"%@ 更新",[formatter stringFromDate: date]];
self.label4.text = dic[@"categoryName"];
}
-(void)addView{
_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 100, 110)];
[self addSubview:_imageView];
_label1 = [[UILabel alloc]initWithFrame:CGRectMake(120, 10, self.frame.size.width - 120, 30)];
_label1.font = [UIFont systemFontOfSize:14];
_label1.textColor = [UIColor lightGrayColor];
_label1.numberOfLines = 0;
[self addSubview:_label1];
_imageView2 =[[UIImageView alloc]initWithFrame:CGRectMake(120, 40, 20, 20)];
_imageView2.layer.cornerRadius = 10;
_imageView2.layer.masksToBounds = YES;
[self addSubview:_imageView2];
_label2 = [[UILabel alloc]initWithFrame:CGRectMake(150, 40, self.frame.size.width- 180, 20)];
_label2.font = [UIFont systemFontOfSize:12];
_label2.textColor = [UIColor lightGrayColor];
[self addSubview:_label2];
_label3 = [[UILabel alloc]initWithFrame:CGRectMake(120, 70, self.frame.size.width- 100, 20)];
_label3.font = [UIFont systemFontOfSize:12];
_label3.textColor = [UIColor lightGrayColor];
[self addSubview:_label3];
_label4 = [[UILabel alloc]initWithFrame:CGRectMake(120, 100, self.frame.size.width- 100, 20)];
_label4.font = [UIFont systemFontOfSize:12];
_label4.textColor = [UIColor lightGrayColor];
[self addSubview:_label4];
NSArray * array = @[@"订阅(609)",@"分享",@"播放"];
for (int i =0; i<array.count; i++) {
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(50 + (self.frame.size.width - 160)/2 * i + 20*i, 130, 20, 20)];
[btn setBackgroundImage:[UIImage imageNamed:@"分享"] forState:UIControlStateNormal];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(i* (self.frame.size.width/3), 180, self.frame.size.width/3, 20)];
label.textAlignment = NSTextAlignmentCenter;
label.center = CGPointMake(btn.center.x, 160);
label.textColor = [UIColor lightGrayColor];
label.text = array[i];
label.font= [UIFont systemFontOfSize:12];
[self addSubview:btn];
[self addSubview:label];
}
}
@end