use*_*630 1 ios uicollectionview swift
我正在使用swift 2.o集合视图.因为每件事都很好.但是当我在不同的屏幕上运行时,每个单元格之间的宽度差异是不同的.我需要在集合视图的每一行中有三个单元格,对于集合视图中的所有单元格,左侧,右侧,顶部,底部有8个px间隙.而且我还需要将单元格设置为角半径.我需要如下图像:[![在此输入图像描述] [1]] [1]
但是,当我在5s屏幕上运行时,我得到这样的6屏幕,如第二张图像:
[![在此处输入图片说明] [2]] [2]
iPhone 6 :
[![在此输入图片说明] [3]] [3]
看到左,右,底,顶之间的间隙与我的第一张图像不同.我需要得到像我的第一张图片.
我在故事板中设置单元格的最小行空间为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.
}
}
Run Code Online (Sandbox Code Playgroud)
从故事板集中CollectionViews Section Inset from size inspector为Top = 8,Bottom = 8,Left = 8和Right = 8,它应该看起来像
并返回单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//If you want your cell should be square in size the return the equal height and width, and make sure you deduct the Section Inset from it.
return CGSizeMake((self.view.frame.size.width/3) - 16, (self.view.frame.size.width/3) - 45);
}
Run Code Online (Sandbox Code Playgroud)
多数民众赞成,没有更多.你应该看到我的结果:
| 归档时间: |
|
| 查看次数: |
5814 次 |
| 最近记录: |