2016-09-19 2 views
0

내 세그먼트 컨트롤 바로 아래에 collectionView를 배치하고 싶지만 제약 조건이 잘못되는지 잘 모릅니다. 또한 전체 프레임 너비에서 10을 뺀 채 collectionView 위에 중점을두기 위해 세그먼트 화 된 컨트롤을 배치하고 싶습니다.UICollectionView 위치 및 분할 컨트롤 프로그래밍 방식으로 오류가 발생했습니다.

을 Heres 코드 내가 시도하고있다 : 여기

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 

내 출력의 이미지입니다. 내 Segmented View가 전체 너비 프레임을 채우기위한 첫 번째보기가되고 내 컬렉션보기가 Segmented 컨트롤 바로 아래에 표시됩니다.

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 프레임 같은 것을 수도 있었죠하지 Collection 뷰에 현재보기에 CustomSc를 추가 할 필요가

self.view.addSubview(collectionView) 
관련 문제