垂直对齐多个视图

时间:2014-10-15 08:00:09

标签: ios objective-c uiview

我要制作看起来像这样的东西:

enter image description here


enter image description here

我有NSArraywalkingcar个对象。
Car类具有NSString属性,其中包含这些数字。

我该怎么做?感谢。

2 个答案:

答案 0 :(得分:0)

您可以通过编程方式创建ImageView和UILabel,并将它们排列在单元格/视图中。

答案 1 :(得分:0)

您可以将UIView创建为容器,左侧为UIImageView,右侧为UITextView。这将是汽车对象的模板。您的行走对象只需要一个简单的UIImageView。然后计算您希望第一个UIImage开始的点,并在前一个元素的末尾添加下一个容器。你也可以创建一个箭头模板,这样你只需要连接你想要的元素。看起来应该是这样的

CGFloat fHeightImage = 20.0f;

UIView *view = 
 [[UIView alloc] initWithFrame:CGRectMake(0, 0,
                                          [UIScreen mainScreen].bounds.size.width,
                                          fHeightImage)];
UIImageView *imageViewCar = 
 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
                                               fHeightImage,
                                               fHeightImage)];
[imageViewCar setImage:[UIImage imageNamed:@"walking"]];
[view addSubview:imageViewCar];
UIImageView *imageViewArrow = 
 [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(imageViewCar.frame),
                                               CGRectGetHeight(imageViewCar.frame),
                                               fHeightImage,
                                               fHeightImage)];
[imageViewArrow setImage:[UIImage imageNamed:@"arrow"]];
[view addSubview:imageViewArrow];
相关问题