简体   繁体   中英

adding UIView into subView of cell, UITableViewController

Im adding 2 texts into a cell of a table. What I am doing is

UITableViewCell *cell =nil;

NSString *CellIdentifier = @"Cell";

cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

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

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

mainLabel.tag = 1003;

mainLabel.text = @"Text 1";

mainLabel.textAlignment = UITextAlignmentLeft;

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

}

I do the same thing to add secondLabel to a cell. 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 )

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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