I would like to place my collectionView right underneath my Segmented Control, however I dont know if I am getting my constraints wrong. I would like to also place my segmented control to fill the whole frame width minus ten but centered above the collectionView.
Heres the code I have been trying:
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
Here is the image of my output. I would my Segmented View to be my first view to fill the whole width frame and my collection view to show right underneath my Segmented control.
Thanks.