【发布时间】:2016-08-08 23:50:47
【问题描述】:
我通过情节提要创建了一个 UICollectionView 并将其临时定位在视图中;但是,我想在启动时以编程方式覆盖位置,而不是使用情节提要配置。
我认为viewDidLoad() 是进行此更改的正确位置吗?
Swift 2 代码:
override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
collectionView.delegate = self
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "collectionCell")
collectionView.backgroundColor = UIColor(white:1, alpha:0.0)
// Doesn't stretch the width to the device's width on launch. :-(
collectionView.frame.size = CGSize(width: UIScreen.mainScreen().bounds.width, height: 200)
}
【问题讨论】:
-
你在使用自动布局吗?您是否从界面构建器中设置了故事板手段的约束?
-
是的,我已经从界面生成器中设置了约束。除了转到情节提要上的 UICollectionView 对象并清除约束之外,不确定如何重置它们,但这无济于事。它不会以编程方式更改宽度。
标签: ios swift uicollectionview width viewdidload