【发布时间】:2016-03-08 09:50:18
【问题描述】:
我正在使用 swift 2.o 集合视图。因为每件事都运行良好。但是当我在不同的屏幕上运行时,每个单元格之间的宽度差距是不同的。我需要在集合视图的每一行中三个单元格,集合视图中的所有单元格的左、右、上、下间隔为 8 px。而且我还需要将单元格设置为角半径。我需要像下图: [![在此处输入图片描述][1]][1]
但是当我在 5s 屏幕上运行时,我会变成这样,而对于 6 屏幕,就像第二张图片一样:
[![在此处输入图片描述][2]][2]
iPhone 6:
[![在此处输入图片描述][3]][3]
看到 left, right, bottom , top 之间的差距不像我的第一张图片那样均匀。我需要像我的第一张照片一样。
我在情节提要中将单元格的最小行间距设置为 6。但我无法像我的第一张图片一样。
请帮帮我。
我的 popvc.swift :
import UIKit
class popVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var tableData: [String] = ["RESTAURANTS", "BANKS", "COFFEE","PIZZA", "HOTELS", "TAXI", "RESTAURANTS", "BANKS","COFFEE","PIZZA", "HOTELS", "TAXI","RESTAURANTS", "BANKS", "COFFEE","PIZZA", "HOTELS", "TAXI"]
var tableImages: [String] = ["img1.png", "img2.png", "img3.png", "img4.png", "img5.png", "img6.png", "img7.png", "img8.png", "img9.png", "img10.png", "img11.png", "img11.png", "img1.png", "img2.png", "img3.png", "img4.png", "img5.png", "img6.png"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tableData.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: colvwCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! colvwCell
cell.lblCell.text = tableData[indexPath.row]
cell.imgCell.image = UIImage(named: tableImages[indexPath.row])
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Cell \(indexPath.row) selected")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
-
检查你的collectionview frame /constratint
-
框架还是约束??对于单元格,我没有设置约束。对于我设置的图像和标签
标签: ios swift uicollectionview