0
我想将我的collectionView放置在我的分段控件下方,但是我不知道是否我的约束错误。我想也将我的分段控件填充整个框架宽度减去十,但集中在collectionView上方。UICollectionView以编程方式位置和分段控制错误
继承人的代码,我一直在努力:
let item = ["Past", "Future"]
let customSC = UISegmentedControl(items: item)
customSC.selectedSegmentIndex = 0
let frame = UIScreen.mainScreen().bounds
customSC.frame = CGRectMake(0, 0,
frame.width, 25)
customSC.layer.cornerRadius = 5.0 // Don't let background bleed
customSC.backgroundColor = MaterialColor.white
customSC.tintColor = MaterialColor.red.accent3
customSC.translatesAutoresizingMaskIntoConstraints = false
//customSC.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor)
//collectionView?.translatesAutoresizingMaskIntoConstraints = false
collectionView?.addSubview(customSC)
customSC.centerXAnchor.constraintEqualToAnchor(collectionView?.centerXAnchor).active = true
//collectionView?.topAnchor.constraintEqualToAnchor(customSC.bottomAnchor,constant: 2).active = true
这里是我输出的图像。我将我的分段视图作为我的第一个视图来填充整个宽度框架和我的集合视图,以显示在我的分段控件下方。
感谢。