Ios 从UICollectionView中删除所有单元格空间
小猪把这件事往后退 如果我改变Ios 从UICollectionView中删除所有单元格空间,ios,swift,ios8,uicollectionview,Ios,Swift,Ios8,Uicollectionview,小猪把这件事往后退 如果我改变 cell.layer.borderWidth = 0.0 它删除单元格顶部和底部的边框,但不会删除左侧和右侧边框。是否有删除所有边框和单元格间距的方法,以使图像完全齐平?我的代码: var collectionView: UICollectionView? var screenSize: CGRect! var screenWidth: CGFloat! var screenHeight: CGFloat! override func viewDidLoad
cell.layer.borderWidth = 0.0
它删除单元格顶部和底部的边框,但不会删除左侧和右侧边框。是否有删除所有边框和单元格间距的方法,以使图像完全齐平?我的代码:
var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
screenSize = UIScreen.mainScreen().bounds
screenWidth = screenSize.width
screenHeight = screenSize.height
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
}
func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellIdentifier", forIndexPath: indexPath) as! CollViewCell
//cell.imageCell.image = UIImage(named: self.gridIMages[indexPath.row])
cell.backgroundColor = UIColor.whiteColor()
cell.layer.borderColor = UIColor.blackColor().CGColor
cell.layer.borderWidth = 0.0
cell.frame.size.width = screenWidth / 3
cell.frame.size.height = screenHeight / 3
return cell
}
您没有在任何位置分配布局。你只是创建它,而不是使用它
因此,您需要在
viewDidLoad
中使用collectionView.collectionViewLayout=layout
。但在interface builder中进行设置可能更容易。谢谢您的关注!因此,添加该行将删除第一列边框。但第二个仍然存在。尝试打印出每个单元格的单元格宽度。可能宽度是320,所有单元格都是106。然后你有两个像素丢失(虽然我只是疯狂猜测)。还应始终使用collectionView.frame.width,而不是ScreenWidth。在您的情况下,它将是相同的,但是如果您决定稍后调整collectionView的大小,那么您的代码将无法工作,这将起作用。