2016-11-01 12 views
0

私は、迅速かつイオスプログラミングを学ぶためにinstagramのようなアプリケーションをプログラミングしてきました。今度は、トップバーになるUIStackViewと、リクエストを送信してイメージを変更する3つのボトムボタンを作成しました。コレクションinstagram app swiftのようなポジショニングを表示

問題点 - 私はCollectionViewで位置、幅、セル間隔を設定できません。私がしたい: CollectionViewすべてのデバイス上の全幅画像間の セル間隔= 1 CollectionViewは、私は今、何をしなければならなかったの

上部バーと下部のボタンの完全な高さの間に配置すべきですか?私のエミュレータの

画面:私のストーリーボードのhttp://prntscr.com/d1mmu1

画面:http://prntscr.com/d1mnhr

私はストーリーボードでこれを行う試みたと思いますが、parametresのすべてを変えていたが、hasntは私の目標を達しました。 同じ高さをCollectionViewとアプリケーションのメインビューに追加すると、すべての画面が表示され、スクロール後に消えます。 どのようにその位置と幅、高さ、およびセルの間隔を設定できますか?

here is a code of my viewcontroller for CollectionView - 

// MARK: - UICollectionViewDataSourceプロトコル

// tell the collection view how many cells to make 
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return self.items.count 
} 

// make a cell for each cell index path 
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
    // get a reference to our storyboard cell 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell 

    // Use the outlet in our custom class to get a reference to the UILabel in the cell 
    cell.imageView.image = UIImage(named: "main/p\(self.items[indexPath.item].code)/main/main.jpg") 
    print("main_card_images/p\(self.items[indexPath.item].code)/main/main") 
    return cell 
} 

// MARK: - UICollectionViewDelegate protocol 

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    // handle tap events 
    print("You selected cell #\(indexPath.item)!") 
    print(self.items[indexPath.item]) 
} 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    let yourNextViewController = (segue.destination as! ViewControllerCard) 
    let indexPath = collectionView.indexPath(for: sender as! UICollectionViewCell) 
    yourNextViewController.mainCardImage = self.items[(indexPath?.item)!] 
} 
+0

私の答えをチェックしhttp://stackoverflow.com/questions/40325327/adjust-cellsize-for-fit-all-screens/40325452#4 0325452 – Joe

答えて

1

は、このコードを試してみてください。

注:コードの下あなたはcolumn.Youの異なる数は、セルの幅と高さで再生したり、私の他の回答を見てする必要がしたいすべてのiPhone models.If上でテストだけのために4列のレイアウトを働くAdjust cellsize for fit all screens?

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { 
    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout 
    layout.sectionInset = UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3) 
    layout.minimumInteritemSpacing = 03 
    layout.minimumLineSpacing = 03 
    layout.invalidateLayout() 

    return CGSize(width: ((self.view.frame.width/4) - 4), height:((self.view.frame.width/4) - 4)); 
} 

出力:

enter image description here

関連する問題