2017-02-26 10 views
0

私はASHorizo​​ntalScrollViewを実装しようとしています(App Strore水平スクロールメニューと同様)。私はフレームを調整していますが、最後の要素は決して表示されません。サイズはスーパービューよりも大きく見えます。それはそこにある最後の要素を見ることができますが、決してそれをもたらすことはできません。ASHorizo​​ntalScrollViewがすべての要素を表示しない

I touch and drag to force to show the last element

私は、それが割り当てられていますテーブルセルのサイズとして水平scrollviewのサイズを設定しました。

私の質問は、どのように水平スクロール幅を設定してすべての要素を表示するのですか?

これは私がCellForRowAtIndexPathでそれを設定する方法である:(ストーリーボードに等しい)フレームとテーブルビューを再調整

internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cellIdentifier = "cell" 
     var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) 

     //First row must be ASHorizontalScrollView 
     if indexPath.row == 0 { 
      let horizontalScrollView = ASHorizontalScrollView.init(frame: CGRect.init(x: 0, y: 0, width: cell.frame.width, height: cell.frame.height)) 


      //sample code of how to use this scroll view 
      horizontalScrollView.uniformItemSize = CGSize(width: 74.4, height: 74.4) 

      //this must be called after changing any size or margin property of this class to get acurrate margin 
      horizontalScrollView.setItemsMarginOnce() 
      //create buttons for cell 1 
      var buttons = [UIView]() 


      var choosedColor : UIColor! 
      //Loop creating buttons and customizing them 
      for i in 0...contacts.count - 1 { 

       var aButton = CustomButton.init(frame: CGRect.init(x: 0, y: 0, width: 74, height: 74)) 

       //Choose a color depending of the index it's showing 
       switch i % contacts.count { 
       case 0: 
        choosedColor = UIColor.init(red: 0.639, green: 0.780, blue: 0.294, alpha: 1.0) 
        break 
       case 1: 
        choosedColor = UIColor.init(red: 0.807, green: 0.258, blue: 0.317, alpha: 1.0) 
        break 
       case 2: 
        choosedColor = UIColor.init(red: 0.286, green: 0.509, blue: 0.772, alpha: 1.0) 
        break 
       default: 
        choosedColor = UIColor.init(red: 0.639, green: 0.780, blue: 0.294, alpha: 1.0) 
       } 

       //set chosen color to button and round it up 
       aButton.backgroundColor = choosedColor 

       aButton.setContactName(contactName: contacts[i]) 

       buttons.append(aButton) 

      } 

      horizontalScrollView.addItems(buttons) 
      var x = horizontalScrollView.calculateMarginBetweenItems() 


      cell.contentView.addSubview(horizontalScrollView) 
      horizontalScrollView.translatesAutoresizingMaskIntoConstraints = false 
      cell.contentView.addConstraint(NSLayoutConstraint.init(item: horizontalScrollView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: cell.frame.height)) 

      cell.contentView.addConstraint(NSLayoutConstraint.init(item: horizontalScrollView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem:cell.contentView, attribute: .width, multiplier: 1, constant: 0)) 




     } 
     else{ 
      //cell must be message cell 


     } 

    return cell 
    } 

答えて

0

正しく

すべての要素を構成
関連する問題