2011-04-18 65 views
3

我對iOS中的用戶界面有疑問,特別是在iPad上。在iOS中使用相對位置佈局視圖的最佳方式?

我的應用程序顯示來自搜索結果的餐廳信息。並非所有字段都是必需的,所以有些字段是空的。他們可能是電話號碼,收視率,菜單等。

所以基本上我想要做的是以佈局格式顯示諸如UILabelUIButton的視圖,但我不想顯示任何視圖空字符串。所以視圖之間不應該有任何空的空間。

我這樣做的方式是,如果一個字段不是空的,我啓動它的視圖,然後顯示在之前顯示的視圖下方,通過跟蹤視圖應該顯示的當前高度。

雖然這有效,但我相信它的工作方式似乎很乏味。有相對位置顯示視圖的最佳做法嗎?

謝謝:)

回答

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 
+0

CSLinearLayoutView是UIScrollView的子類。我覺得奇怪把它添加到UITableViewCell。所以我想知道如果你真的使用這個庫與UITableViewCell。謝謝。 :) – nonamelive 2013-02-28 05:10:33

+0

是的,它可以在UITableViewCell中使用,並且我一直都以這種方式使用它。如果內容處於線性佈局視圖的範圍內,則它的行爲與沒有滾動的普通視圖相似。 – user2393462435 2013-02-28 20:39:47

+0

謝謝!我會試試看!尼斯圖書館btw。哦,你是否需要生成一個虛擬佈局視圖才能在tableView:heightForRowAtIndexPath:方法中使用它? :) – nonamelive 2013-03-01 01:56:21

相關問題