iOS中使用UItableviewcell实现团购和微博界面的示例

2020-01-14 18:26:55于海丽

        UILabel *introLabel = [[UILabel alloc] init];
        introLabel.font = NJTextFont;
        introLabel.numberOfLines = 0;
        // introLabel.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:introLabel];
        self.introLabel = introLabel;
        
        // 5.创建配图
        UIImageView *pictureView = [[UIImageView alloc] init];
        [self.contentView addSubview:pictureView];
        self.pictureView = pictureView;
        
    }
    return self;
}


- (void)setWeiboFrame:(NJWeiboFrame *)weiboFrame
{
    _weiboFrame = weiboFrame;
    
    // 1.给子控件赋值数据
    [self settingData];
    // 2.设置frame
    [self settingFrame];
}


/**
 *  设置子控件的数据
 */
- (void)settingData
{
    NJWeibo *weibo = self.weiboFrame.weibo;
    
    // 设置头像
    self.iconView.image = [UIImage imageNamed:weibo.icon];
    // 设置昵称
    self.nameLabel.text = weibo.name;
    // 设置vip
    if (weibo.vip) {
        self.vipView.hidden = NO;
        self.nameLabel.textColor = [UIColor redColor];
    }else
    {
        self.vipView.hidden = YES;
        self.nameLabel.textColor = [UIColor blackColor];
    }
    // 设置内容
    self.introLabel.text = weibo.text;
    
    // 设置配图
    if (weibo.picture) {// 有配图
        self.pictureView.image = [UIImage imageNamed:weibo.picture];
        self.pictureView.hidden = NO;
    }else
    {
        self.pictureView.hidden = YES;