Ich bin ein Android-Entwickler und meine erste iOS
App zu entwickeln, muss ich GridView implementieren, um einige soziale Symbol hinzufügen, so nach einer Suche habe ich UICollectionView
gefunden, aber es funktioniert nicht wie erwartet. Wie wird die dynamische Höhe der UICollection-Ansicht festgelegt? Eigentlich möchte ich alle Icons anzeigen, aber es zeigt nur eine Reihe und andere nach dem Scrollen der UICollectionView.Dynamische UICollectionView in UIViewController
unten ist das Beispiel: Dies ist, was ich
Das ist, was ich will mich immer:
ich unten Code verwenden:
import UIKit
class CollectionViewDemo: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var socialHandleCollection: UICollectionView!
@IBOutlet weak var socialImageView: UIImageView!
var socialHandleArray:[String] = ["Facebook", "Twitter", "Youtube","Vimeo", "Instagram", "Custom URL", "Linkedin", "pinterest"]
override func viewDidLoad() {
self.socialHandleCollection.delegate = self
self.socialHandleCollection.dataSource = self
// socialHandleCollection.frame.size.height = 130
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return socialHandleArray.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: colvwCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! colvwCell
cell.imgCell.image = UIImage(named: "demo_img.png")
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print(self.socialHandleArray[indexPath.row])
}
}
Jede Hilfe wäre willkommen.
können Sie autoLayout verwenden? –
Auto-Layout verwenden: und Ausgangshöhe für diese Sammelansicht, Höhe: NSLayoutConstraint! -> danach Height.constant = 52 (gemäß Ihrer Anforderung) –