CollectionView作为Swift中的子视图
我尝试将一个非常简单的collectionView作为子视图插入,但无法获得正确的框架。我究竟做错了什么?你能帮帮我吗?
这是我的代码:
import UIKit
class ViewController: UIViewController {
var collectionView: UICollectionView!
@IBOutlet weak var testView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
setupCollectionView()
}
func setupCollectionView() {
let layout = UICollectionViewFlowLayout()
collectionView = UICollectionView(frame: testView.frame, collectionViewLayout: layout)
collectionView.backgroundColor = UIColor.green
testView.addSubview(collectionView)
}
}
答案 0 :(得分:4)
dataGridView1.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.Black;
问题是" testView.frame"那。 testview框架x和y指向不是0