// MyweiboOriginalView.h
// 新浪微博
//
// Created by Jose on 15-4-20.
// Copyright (c) 2015年 jose. All rights reserved.
//
#import <UIKit/UIKit.h>
@class MyweiboOriginalFrame;
@interface MyweiboOriginalView : UIView
/** 原创微博frame通过set的方法来设置view */
@property(nonatomic,strong)MyweiboOriginalFrame *originalframe;
@end
*****************************************************************************************************************************
*****************************************************************************************************************************
*****************************************************************************************************************************
//
// MyweiboOriginalView.m
// 新浪微博
//
// Created by Jose on 15-4-20.
// Copyright (c) 2015年 jose. All rights reserved.
// 原创微博的view
#import "MyweiboOriginalView.h"
#import "MyWeiboModel.h"
#import "MyUserModel.h"
#import "UIImageView+WebCache.h"
#import "MyweiboOriginalFrame.h"
#import "Global.h"
@interface MyweiboOriginalView()
/** 原创微博的头像 */
@property(nonatomic,weak)UIImageView *icon;
/** 原创微博的昵称 */
@property(nonatomic,weak)UILabel *namelabel;
/** 原创微博发表的时间 */
@property(nonatomic,weak)UILabel *timelabel;
/** 原创微博发布的来源 */
@property(nonatomic,weak)UILabel *sourcelabel;
/** 原创微博的正文 */
@property(nonatomic,weak)UILabel *textlabel;
/** vip会员图标 */
@property(nonatomic,weak)UIImageView *vipview;
@end
@implementation MyweiboOriginalView
#pragma mark
//初始化子控件
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
//1.头像
UIImageView *icon=[[UIImageView alloc]init];
[self addSubview:icon];
_icon=icon;
//2.昵称
UILabel *namelabel=[[UILabel alloc]init];
[self addSubview:namelabel];
namelabel.font=OriginalName;
_namelabel=namelabel;
//3.会员图标
UIImageView *vipview=[[UIImageView alloc]init];
vipview.contentMode=UIViewContentModeCenter;
[self addSubview:vipview];
_vipview=vipview;
//4.时间
UILabel *timelabel=[[UILabel alloc]init];
[self addSubview:timelabel];
timelabel.textColor=[UIColor orangeColor];
timelabel.font=OriginalTime;
_timelabel=timelabel;
//5.来源
UILabel *sourcelabel=[[UILabel alloc]init];
//sourcelabel.textColor=[UIColor orangeColor];
sourcelabel.font=OriginalSource;
[self addSubview:sourcelabel];
_sourcelabel=sourcelabel;
//6.正文
UILabel *textlabel=[[UILabel alloc]init];
textlabel.font=OrigibnalText;
textlabel.numberOfLines=0;
[self addSubview:textlabel];
_textlabel=textlabel;
}
return self;
}
//传入微博frame数据通过set的方法来设置frame
-(void)setOriginalframe:(MyweiboOriginalFrame *)originalframe{
_originalframe=originalframe;
//初始化当前的self的frame
self.frame=originalframe.originalframe;
//原创微博的数据
MyWeiboModel *weibomodel=originalframe.originalweibo;
MyUserModel *usermodel=weibomodel.user;
//1.头像
_icon.frame=originalframe.iconframe;
[self.icon sd_setImageWithURL:[NSURL URLWithString:usermodel.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small@2x"]];
//2.昵称
_namelabel.text=usermodel.name;
_namelabel.frame=originalframe.nameframe;
//判断是否为会员类型
if (usermodel.isvip) {
_namelabel.textColor=[UIColor orangeColor];
_vipview.hidden=NO;
_vipview.frame=originalframe.vipiconframe;
_vipview.image=[UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%d",usermodel.mbrank]];
}
else{
_vipview.hidden=YES;
_namelabel.textColor=[UIColor blackColor];
}
//3.时间
NSString *time=weibomodel.created_at;
_timelabel.text=time;
CGFloat timex=CGRectGetMinX(_namelabel.frame);
CGFloat timey=CGRectGetMaxY(_namelabel.frame)+CellMargin*0.5;
CGSize timesize=[time sizeWithFont:OriginalTime];
_timelabel.frame=(CGRect){{timex,timey},timesize};
//4.来源
_sourcelabel.text=weibomodel.source;
CGFloat sourcex=CGRectGetMaxX(_timelabel.frame)+CellMargin;
CGFloat sourcey=timey;
CGSize sourcesize=[weibomodel.source sizeWithFont:OriginalSource];
_sourcelabel.frame=(CGRect){{sourcex,sourcey},sourcesize};
/***
//3.时间
_timelabel.text=weibomodel.created_at;
_timelabel.frame=originalframe.timeframe;
//4.来源
_sourcelabel.text=weibomodel.source;
_sourcelabel.frame=originalframe.sourceframe;
****/
//5.正文
_textlabel.text=weibomodel.text;
_textlabel.frame=originalframe.textframe;
}
@end