简体   繁体   English

将UIView添加到单元格的子视图UITableViewController中

[英]adding UIView into subView of cell, UITableViewController

Im adding 2 texts into a cell of a table. 我将2个文本添加到表格的单元格中。 What I am doing is 我在做什么

UITableViewCell *cell =nil; UITableViewCell * cell = nil;

NSString *CellIdentifier = @"Cell"; NSString * CellIdentifier = @“Cell”;

cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) { if(cell == nil){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]; reuseIdentifier:CellIdentifier];

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

mainLabel.tag = 1003; mainLabel.tag = 1003;

mainLabel.text = @"Text 1"; mainLabel.text = @“Text 1”;

mainLabel.textAlignment = UITextAlignmentLeft; mainLabel.textAlignment = UITextAlignmentLeft;

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

} }

I do the same thing to add secondLabel to a cell. 我做同样的事情是将secondLabel添加到单元格中。 What is displaying on the simulator is 在模拟器上显示的是 在此输入图像描述

Now the problem is the background of 2 UILabel is not the same with the background of the cell ( my cells are grouped in the table view ) 现在的问题是2 UILabel的背景与单元格的背景不同(我的单元格在表格视图中分组)

Does anyone know how to fix this problem. 有谁知道如何解决这个问题。

Any comments are welcomed here Thanks 欢迎任何评论在这里谢谢

If I have understand well the question, you need to delete the UILabel background because you want to show the UITableViewCell background instead. 如果我完全理解了这个问题,你需要删除 UILabel背景,因为你想要显示UITableViewCell背景。 So I think you only have to do that: 所以我认为你只需这样做:

 mainLabel.backgroundColor = [UIColor clearColor];

Like the answer above, you should set the same color for both of the view. 与上面的答案一样,您应该为两个视图设置相同的颜色。

cell.backgroundColor = [UIColor clearColor];

or you can set the color of the View you set. 或者您可以设置您设置的视图的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM