gpt4 book ai didi

objective-c - 在 iOS 中使用相对位置布局 View 的最佳方式?

转载 作者:可可西里 更新时间:2023-11-01 17:02:36 24 4
gpt4 key购买 nike

我对 iOS 中的用户界面有疑问,尤其是在 iPad 上。

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

所以基本上我想做的是以布局格式显示 UILabelUIButton 等 View ,但我不想显示任何 View 空字符串。因此 View 之间不应有任何空白。

我的做法是,如果一个字段不为空,我启动它的 View ,然后通过跟踪 View 应显示的当前高度显示在先前显示的 View 下方。

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

谢谢你:)

最佳答案

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

关于objective-c - 在 iOS 中使用相对位置布局 View 的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5698306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com