新浪微博客户端(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
时间: 2024-12-23 04:13:18

新浪微博客户端(22)-创建微博Cell的相关文章

新浪微博客户端(30)-制作微博中的九宫格相册图片

DJStatusPhotosView.h #import <UIKit/UIKit.h> @interface DJStatusPhotosView : UIView @property (nonatomic,strong) NSArray *photos; /** 根据相册图片个数计算相册尺寸 */ + (CGSize)sizeWithCount:(NSUInteger)count; @end DJStatusPhotosView.m #import "DJStatusPhotos

新浪微博客户端(55)-高亮显示微博内容中的昵称,话题,超链接

DJStatus.h #import <Foundation/Foundation.h> @class DJUser; /** 微博 */ @interface DJStatus : NSObject /** 微博id */ @property (nonatomic,copy) NSString *idstr; /** 微博内容 */ @property (nonatomic,copy) NSString *text; /** 微博内容(带属性) */ @property (nonatomic

新浪微博客户端(56)-拼接微博内容中的昵称,超链接,表情图片

DJStatusPart.h #import <Foundation/Foundation.h> @interface DJStatusPart : NSObject /** 文本块内容 */ @property (nonatomic,copy) NSString *text; /** 文本块范围 */ @property (nonatomic,assign) NSRange range; /** 当前文本块是否是特殊文本(昵称,超链接,Emoji) */ @property (nonatom

新浪微博客户端(6)-创建首页下拉菜单

创建首页下拉菜单,本节先完成下拉菜单界面的创建,下节再微调其位置. DJDropdownMenu.h #import <UIKit/UIKit.h> @interface DJDropdownMenu : UIView /** 构造方法 */ + (instancetype)menu; /** 显示 */ - (void)show; /** 消失 */ - (void)dismiss; @property (nonatomic,weak) UIView *contentView; @prope

新浪微博客户端(29)-格式化微博来源显示

DJStatus.m // 更新来源显示 - (void)setSource:(NSString *)source { NSRange range; range.location = [source rangeOfString:@">"].location + 1; range.length = [source rangeOfString:@"<" options:NSBackwardsSearch].location - range.location;

android开发新浪微博客户端 完整攻略 [新手必读]

开始接触学习android已经有3个礼拜了,一直都是对着android的sdk文档写Tutorials从Hello World到Notepad Tutorial算是初步入门了吧,刚好最近对微博感兴趣就打算开发个android版本的新浪微博客户端作为练手项目,并且以随笔的方式详细的记录开发的全过程.本人对java语言以及eclipse Ide都是初次应用基本上属于边学边用,做移动设备上的东西也是第一次,总的来说属于无基础.无经验.无天赋的纯三无人员,还请广大同学们多多给予指点. 开发第一件事情,那

[iOS微博项目 - 4.0] - 自定义微博cell

github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内容包含:原创内容.转发内容 2.思路 使用分层控件,逐层实现 分离model和view model:数据模型.frame模型 view:就是控件本身 frame模型:包含数据模型和子控件frame 根据数据模型来决定子控件是否显示(例如转发内容) cell的view设计雏形: 控件的成员属性层次:

Android新浪微博客户端(四)——添加多个账户及认证

原文出自:方杰| http://fangjie.sinaapp.com/?p=75 转载请注明出处 最终效果演示:http://fangjie.sinaapp.com/?page_id=54 该项目代码已经放到github:https://github.com/JayFang1993/SinaWeibo 二.获取用户信息并保存数据库 上面说到加载AuthActivity有两种情况,其中一种就是授权成功回调,在授权回调成功后我们就开始通过微博API获取用户信息了,然后保存数据库了.这一系列操作我采

Android新浪微博客户端(六)——Home界面的ListView

原文出自:方杰|http://fangjie.sinaapp.com/?p=184转载请注明出处 最终效果演示:http://fangjie.sinaapp.com/?page_id=54该项目代码已经放到github:https://github.com/JayFang1993/SinaWeibo 一.首先是ListView的adapter. 因为微博列表的Item不是规则的,比如说有些微博有转发子微博,有些没有,有些有图片,有些没有图片,所以说很不固定.这里就采用BaseAdapter,要自