考虑到下面的图像,对象B需要基于其内部的UILabel数量来动态调整高度。 然后,物体B高度必须影响物体C的高度。
我目前在故事板中实现了这个但是我坚持这两件事,对象B应该由什么组成? (我不能使用堆栈视图,因为我的部署目标是7.1) 它需要有重复列表
[uiview] - [uilabel]
对象C是一个UIView,我想要对象B的高度来影响它的高度?我怎么能实现呢?
答案 0 :(得分:1)
您可以使用此类代码
int lblY = 10; // As per your requirement
int viewBHT = 50; // As per your requirement
UILabel *lbl;
NSMutableArray *arrLbl = [[NSMutableArray alloc] initWithObjects:@"1",@"1",@"1",@"1",@"1",@"1", nil];
UIView *viewB = [[UIView alloc] init];
[viewB setFrame:CGRectMake(0, viewA.frame.origin.y, self.view.frame.size.width, viewBHT)];
[viewB setBackgroundColor:[UIColor darkGrayColor]];
[self.view addSubview:viewB];
for (int i = 0; i < arrLbl.count; i++)
{
lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, lblY , viewB.frame.size.width - 20, 30)];
[lbl setText:[NSString stringWithFormat:@"Hello %d",i]];
[lbl setBackgroundColor:[UIColor lightGrayColor]];
[viewB addSubview:lbl];
lblY = lblY + lbl.frame.size.height + 10;
}
viewBHT = lbl.frame.size.height + lbl.frame.origin.y + 10;
[viewB setFrame:CGRectMake(0, 80, self.view.frame.size.width, viewBHT)];
UIView *viewC = [[UIView alloc] init];
[viewC setFrame:CGRectMake(0, viewB.frame.origin.y + viewB.frame.size.height + 10, self.view.frame.size.width, 50)];
[viewC setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:viewC];
希望这会对你有所帮助.. !! :)