任何人都可以告诉我如何为我在 UITableView Cell 上添加的 View 添加两个标签。我已将该 View 创建为具有某个名称的 UIView。并且我已在 UIView 类中创建了两个标签,并为标签设置了框架,设置文本等。我的问题是在表格 View 单元格中获取该 View ,而不是那些标签。
countLabel.text = @"4";
countLabel.frame=CGRectMake(275, 10, 20, 15);
countLabel.font=[UIFont boldSystemFontOfSize:15.0];
countLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5];
countLabel.backgroundColor=[UIColor clearColor];
hrsLabel.text = @"Hours";
hrsLabel.frame=CGRectMake(260, 30, 45, 15);
hrsLabel.font=[UIFont boldSystemFontOfSize:15.0];
hrsLabel.textColor=[UIColor colorWithWhite:0.0 alpha:0.5];
hrsLabel.backgroundColor=[UIColor clearColor];
这只是我正在将框架、文本设置为 UIView 中的标签。
GreenView *greenView = [[GreenView alloc] initWithFrame:CGRectMake(250, 8, 60, 50)];
greenView.backgroundColor = [UIColor colorWithRed:0.000 green:0.690 blue:0.313 alpha:0.5];
[cell.contentView addSubview:greenView];
在这里,我将该 UIView 添加到 tableview 单元格中。我不知道如何将这些标签添加到我的 UIView 中。请帮助我。
抱歉,如果有任何英语错误。 请任何人帮助我。 提前非常感谢。
最佳答案
创建 label 和 label1 等标签并添加到 UIView
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 250, 15)];
[label setText:@"Hello"];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 250, 15)];
[label1 setText:@"Hello1"];
UIView *myView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[myView addSubview:label];
[myView addSubview:label1];
关于iphone - 将标签作为 subview 添加到 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072257/