在iOS中使用相对位置布局视图的最佳方法?

Rya*_*Rho 3 layout user-interface view objective-c ios

我对iOS中的用户界面有疑问,特别是在iPad上.

我的应用程序显示搜索结果中的餐馆信息.并非所有字段都是必需的,因此某些字段为空.它们可以是电话号码,评级,菜单等.

所以基本上我想要做的是显示诸如UILabelUIButton布局格式的视图,但我不想显示任何带有空字符串的视图.所以视图之间不应该有空格.

我这样做的方法是,如果一个字段不是空的,我会启动它的视图,然后通过跟踪应该显示视图的当前高度来显示在先前显示的视图下方.

虽然这有效,但我相信它的工作方式似乎乏味.是否有显示相对位置视图的最佳实践?

谢谢 :)

use*_*435 7

我已经创建了一个库来解决这个问题:CSLinearLayoutView

你这样使用它:

// create the linear layout view
CSLinearLayoutView *linearLayoutView = [[[CSLinearLayoutView alloc] initWithFrame:self.view.bounds] autorelease];
linearLayoutView.orientation = CSLinearLayoutViewOrientationVertical;
[self.view addSubview:linearLayoutView];

// create a layout item for the view you want to display and add it to the layout view
CSLinearLayoutItem *item = [CSLinearLayoutItem layoutItemForView:someView];
item.padding = CSLinearLayoutMakePadding(5.0, 10.0, 5.0, 10.0);
item.horizontalAlignment = CSLinearLayoutItemHorizontalAlignmentCenter;
item.fillMode = CSLinearLayoutItemFillModeNormal;
[linearLayoutView addItem:item];

// add more items
Run Code Online (Sandbox Code Playgroud)