2016-09-19 17 views
0

私のセグメント化されたコントロールのすぐ下にコレクションビューを配置したいと思いますが、制約が間違っているかどうかはわかりません。また、フレーム幅全体から10を引いたものの、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 

をここでは私の出力の画像です。セグメント化されたコントロールのすぐ下に表示するように、全体の幅のフレームとコレクションのビューを塗りつぶす最初のビューになりました。

enter image description here

感謝。

答えて

0

あなたは今、この

のように現在のビューにCollectionviewを追加し、この

collectionView.frame = CGRectMake(0, customSC.frame.origin.y + 25, self.view.frame.size.width, set Acc. to your req.) 

のようなこの

self.view.addSubview(customSC) 

セットCollectionViewフレームのようなもの.doというないコレクションビューに現在のビューにCustomScを追加する必要があります

self.view.addSubview(collectionView) 
関連する問題