【问题标题】:adding UIView into subView of cell, UITableViewController将 UIView 添加到单元格的子视图中,UITableViewController
【发布时间】:2012-05-12 03:43:18
【问题描述】:

我将 2 个文本添加到表格的一个单元格中。我正在做的是

UITableViewCell *cell =nil;

NSString *CellIdentifier = @"Cell";

cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

如果(单元格 == nil){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
重用标识符:CellIdentifier];

[[UILabel alloc] initWithFrame:CGRectMake(80.0, 0.0, 220.0, 10.0)];

mainLabel.tag = 1003;

mainLabel.text = @"文本 1";

mainLabel.textAlignment = UITextAlignmentLeft;

mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:mainLabel];

}

我做同样的事情来添加 secondLabel 到一个单元格。 模拟器上显示的是

现在的问题是2个UILabel的背景和单元格的背景不一样(我的单元格是在表格视图中分组的)

有谁知道如何解决这个问题。

这里欢迎任何 cmets 谢谢

【问题讨论】:

    标签: ios uitableview uilabel


    【解决方案1】:

    如果我很好地理解了这个问题,您需要删除 UILabel 背景,因为您想改为显示 UITableViewCell 背景。所以我认为你只需要这样做:

     mainLabel.backgroundColor = [UIColor clearColor];
    

    【讨论】:

      【解决方案2】:

      和上面的答案一样,你应该为两个视图设置相同的颜色。

      cell.backgroundColor = [UIColor clearColor];
      

      或者你可以设置你设置的视图的颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-03
        • 1970-01-01
        相关资源
        最近更新 更多