新浪微博开发之二十九(原创微博view)

//
//  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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值