【发布时间】:2014-10-02 10:35:04
【问题描述】:
我正在制作一个在 iPad 上显示多个图像的项目,我的问题是我无法使 UICollectionView 调整到屏幕大小,并且当它旋转到横向时,自动布局不起作用,我真的很迷茫,非常欢迎任何帮助。
这是我在 Git 上制作的一个简单示例:Git project link
这里有一些代码:
class ViewController: UIViewController {
@IBOutlet weak var mainMenuCollectionView: UICollectionView!
var images = ["220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg","220.jpg"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int
{
return images.count
}
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
{
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as HomeCollectionViewCell
cell.imageView.image = UIImage(named:images[indexPath.row])
cell.textLabel.text = "Woof Woof"
return cell
}
}
提前致谢。
【问题讨论】:
标签: ios xcode swift autolayout xcode6