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

发布于 2024-11-02 03:38:33 字数 350 浏览 0 评论 0原文

我有一个关于 iOS 用户界面的问题,尤其是 iPad 上的用户界面。

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

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

我所做的方法是,如果字段不为空,我会启动其视图,然后通过跟踪应显示视图的当前高度来显示在先前显示的视图下方。

虽然这可行,但我认为它的工作方式似乎很乏味。是否有显示具有相对位置的视图的最佳实践?

谢谢 :)

I have a question about user interface in iOS, especially on iPad.

My app displays restaurant information from a search result. Not all fields are required, so some fields are empty. They could be phone numbers, ratings, menus, and etc.

So basically what I would like to do is to display views such as UILabel and UIButton in a layout format, but I don't want to display any views with empty string. So there should not be any empty space between views.

The way I do is if a field is not empty, I initiate its view and then display below the previously displayed view by keeping track of the current height a view should be displayed.

Although this works, I believe that the way it works seems tedious. Is there the best practice for displaying views with relative positions?

Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

策马西风 2024-11-09 03:38:33

我创建了一个库来解决这个问题: 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

I've created a library to solve just this problem: CSLinearLayoutView

You use it like this:

// 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
悲喜皆因你 2024-11-09 03:38:33

一种方法是使用 UITableView 并遵循此答案中的说明:
自动调整 UITableViewCell高度取决于 Objective-C 中的内容

A way to do that is to use UITableView and follow what is said in this answer:
Auto adjust the UITableViewCell height depend on its contents in Objective-C

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文