I’ve been programming app like instagram for learn swift and ios programming. Now I’d created UIStackView that would be a top bar, and 3 bottom buttons that posts requests and change images.
The problem that I have - I can’t set position, width and delete cell spacing on CollectionView. I want to: CollectionView full width on all devices cell spacing between images = 1 CollectionView should be positioned between top bar and bottom buttons full height
What did I have now?
screen of my emulator: http://prntscr.com/d1mmu1
screen of my storyboard: http://prntscr.com/d1mnhr
I’d tried do this with StoryBoard, had changed all of parametres but hasnt reached my goals. If I add equal height to CollectionView and main view of app it takes all screen and after scrolling it disapears… How can I set that position and width, height, and cell spacing on it?
here is a code of my viewcontroller for CollectionView -
// MARK: - UICollectionViewDataSource protocol
// 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)!]
}