2015-12-30 58 views
2

我如何在垂直滾動中顯示不同的對象?該模式應該是:標題(標籤),字幕,說明(UITextView?),可能是文字中的一些圖像。如何在垂直UIScrollView中顯示文本和其他對象?

我試圖做一個設計類似iChemistry app

的問題是,TextView的支持滾動,因爲它已經UIScrollView中的孩子。其次,我只是在垂直方向上遇到了一些問題,顯然UIScrollView只支持水平滾動到我的UITextView。

如何在UIScrollView中顯示不同的對象和多行文本? (就像我化學應用程序)。我還在.app中檢查了它的文件,它從.sqlite數據庫中獲取原始內容,因此它不使用HTML。

編輯:建議使用TableView?

+3

看起來像一個很好的候選人一個UITableView。 –

+0

爲什麼你的描述是'UITextView'而不是'UILabel'? – rmaddy

+0

我認爲UITableView選項。現在最好的方式來展示真正不同類型的細胞? – BlackBox

回答

1

你的問題不清楚。你想啓用垂直滾動到UITextView &禁用水平滾動?

對於其他問題:

  1. 嘗試的UITableView,使用不同的自定義單元格。

    或者

  2. 簡單,使用的UIView,增加scrollView.contentSize。

下面是如何在一個UITableView中使用不同的定製單元:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if(indexPath.section==0) 
     { 
      static NSString *simpleTableIdentifier = @"SimpleTableCell"; 
      FirstCustomCell *cell = (FirstCustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
      if (cell == nil) 
      { 
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstCustomCell" owner:self options:nil]; 
       cell = [nib objectAtIndex:0]; 
      } 
      cell.textLabel.text= @"FirstCustomCellText"; 
      return cell; 
     } 
     else 
     { 
     static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

      SecondCustomCell *cell = (SecondCustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
      if (cell == nil) 
      { 
       NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SecondCustomCell" owner:self options:nil]; 
       cell = [nib objectAtIndex:0]; 
      } 
      cell.textLabel.text= @"SecondCustomCellText"; 
      return cell; 
     } 
     } 
+0

我想用不同的自定義單元格的UITableView,我得到了一個結果。現在的問題是,我怎麼能有兩種不同類型的自定義單元格?我設法做到一個。 – BlackBox

+0

爲不同的部分使用不同的自定義單元格,就像我在回答中向您展示的那樣。在示例中,我只使用了兩個自定義單元格,您可以使用任意數量的自定義單元格。 –

+0

它適合你嗎? –

0

你可以試試UICollectionView的單元格。

+0

在單元格內使用UICollectionView有什麼優勢? – BlackBox

相關問題