【问题标题】:UIlabel with Custom cell not appear带有自定义单元格的 UIlabel 不会出现
【发布时间】:2014-04-04 16:16:24
【问题描述】:

我很困惑!这不是我第一次创建自定义单元格但这次 UILabel 没有出现我不知道问题出在哪里?

这是自定义单元格 Cell.m

        mainView = [[UIView alloc] initWithFrame:CGRectZero];
        mainView.backgroundColor = [UIColor colorWithRed:249.0/255.0 green:249.0/255.0 blue:249.0/255.0 alpha:1.0];
        profile = [[UIImageView alloc] initWithFrame:CGRectZero];
        profile.layer.masksToBounds = YES;
        profile.layer.cornerRadius = 22.5;
        profile.layer.borderColor = [UIColor whiteColor].CGColor;
        profile.layer.borderWidth = 1.0f;
        profile.clipsToBounds = YES;
        tweet_is = [[UILabel alloc] initWithFrame:CGRectZero];
        tweet_is.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:20];
        tweet_is.backgroundColor = [UIColor clearColor];
        tweet_is.textColor = [UIColor blackColor];
        [self.mainView addSubview:tweet_is];
        [self.mainView addSubview:profile];
        [self.contentView addSubview:self.mainView];

-(void)layoutSubviews {

    [super layoutSubviews];
    self.mainView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 10.0f);
    self.profile.frame = CGRectMake(15, 15, 45, 45);
    self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 300.0f);

} 

这是表格视图

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.tweet_is.text = @"Not approve";
    return cell;
}

【问题讨论】:

  • 我做了一个测试来改变UILabel的背景颜色,它显示没有TEXT的背景颜色!

标签: ios iphone objective-c uitableview uilabel


【解决方案1】:

改变这一行:

self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 300.0f);

设置self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 30.0f);

如果您的单元格高度小于 300(我认为是),那么您将看不到文本。让我知道这是否有帮助.. :)

【讨论】:

    猜你喜欢
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多