新浪微博客户端(22)-创建微博Cell

 

DJStatusCell.h

#import <UIKit/UIKit.h>

@class DJStatusCellFrame;
@interface DJStatusCell : UITableViewCell

/** DJStatusCell 的默认构造方法 */
+ (instancetype)cellWithTableView:(UITableView *)tableView;


@property (nonatomic,strong) DJStatusCellFrame *statusFrame;


@end

 

DJStatusCell.m

#import "DJStatusCell.h"
#import "DJStatusCellFrame.h"
#import "DJStatus.h"
#import "DJUser.h"
#import "UIImageView+WebCache.h"


@interface DJStatusCell()


//============================== 原创微博部分 ========================================

/** 原创微博整体 */
@property (nonatomic,weak) UIView *originalView;
/** 头像 */
@property (nonatomic,weak) UIImageView *iconView;
/** 会员标志 */
@property (nonatomic,weak) UIImageView *vipView;
/** 微博图片 */
@property (nonatomic,weak) UIImageView *photoView;
/** 昵称 */
@property (nonatomic,weak) UILabel *nameLabel;
/** 发布时间 */
@property (nonatomic,weak) UILabel *timeLabel;
/** 微博来源 */
@property (nonatomic,weak) UILabel *sourceLabel;
/** 微博内容 */
@property (nonatomic,weak) UILabel *contentLabel;

//============================== 原创微博部分 ========================================


@end


@implementation DJStatusCell



+ (instancetype)cellWithTableView:(UITableView *)tableView {

    static NSString *ID = @"status";
    
    DJStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[DJStatusCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}



/** cell的默认初始化方法,此方法只会被调用一次 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        
        // 原创微博整体
        UIView *originalView = [[UIView alloc] init];
        [self.contentView addSubview:originalView];
        self.originalView = originalView;
        
        // 头像
        UIImageView *iconView = [[UIImageView alloc] init];
        [self.originalView addSubview:iconView];
        self.iconView = iconView;
        
        // 会员标志
        UIImageView *vipView = [[UIImageView alloc] init];
        [self.originalView addSubview:vipView];
        self.vipView = vipView;
        
        // 微博图片
        UIImageView *photoView = [[UIImageView alloc] init];
        [self.originalView addSubview:photoView];
        self.photoView = photoView;
        
        // 昵称
        UILabel *nameLabel = [[UILabel alloc] init];
        [self.originalView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        // 发布时间
        UILabel *timeLabel = [[UILabel alloc] init];
        [self.originalView addSubview:timeLabel];
        self.timeLabel = timeLabel;
        
        // 微博来源
        UILabel *sourceLabel = [[UILabel alloc] init];
        [self.originalView addSubview:sourceLabel];
        self.sourceLabel = sourceLabel;
        
        // 微博内容
        UILabel *contentLabel = [[UILabel alloc] init];
        [self.originalView addSubview:contentLabel];
        self.contentLabel = contentLabel;
        
        
    }
    return self;

}


- (void)setStatusFrame:(DJStatusCellFrame *)statusFrame {

    _statusFrame = statusFrame;
    
    DJStatus *status = statusFrame.status;
    DJUser *user = status.user;
    
    
    /* 设置当前View的Frame */
    
    // 原创微博整体
    self.originalView.frame = statusFrame.originalViewF;
    
    // 头像
    self.iconView.frame = statusFrame.iconViewF;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]];
    
    // 会员标志
    self.vipView.frame = statusFrame.vipViewF;
    [self.vipView setImage:[UIImage imageNamed:@"common_icon_membership_level1"]];
    
    // 微博图片
    self.photoView.frame = statusFrame.photoViewF;
    
    
    // 昵称
    self.nameLabel.frame = statusFrame.nameLabelF;
    self.nameLabel.text = user.name;
    
    
    // 发布时间
    self.timeLabel.frame = statusFrame.timeLabelF;
    
    
    // 微博来源
    self.sourceLabel.frame = statusFrame.sourceLabelF;
    
    
    // 微博内容
    self.contentLabel.frame = statusFrame.contentLabelF;
    self.contentLabel.text = status.text;


}




@end

DJStatusCellFrame.h

#import <Foundation/Foundation.h>


@class DJStatus;
@interface DJStatusCellFrame : NSObject


/** 微博数据实体 */
@property (nonatomic,strong) DJStatus *status;


/** 原创微博整体的Frame */
@property (nonatomic,assign) CGRect originalViewF;
/** 头像的Frame */
@property (nonatomic,assign) CGRect iconViewF;
/** 会员标志的Frame */
@property (nonatomic,assign) CGRect vipViewF;
/** 微博图片的Frame */
@property (nonatomic,assign) CGRect photoViewF;
/** 昵称的Frame */
@property (nonatomic,assign) CGRect nameLabelF;
/** 发布时间的Frame */
@property (nonatomic,assign) CGRect timeLabelF;
/** 微博来源的Frame */
@property (nonatomic,assign) CGRect sourceLabelF;
/** 微博内容的Frame */
@property (nonatomic,assign) CGRect contentLabelF;


/** 当前微博的高度 */
@property (nonatomic,assign) CGFloat cellHeight;



@end

 

DJStatusCellFrame.m

#import "DJStatusCellFrame.h"

@implementation DJStatusCellFrame


- (void)setStatus:(DJStatus *)status {

    _status = status;
    
    
    
    

}



@end

 

posted @ 2016-11-08 21:20  夜行过客  阅读(347)  评论(0编辑  收藏  举报