2017-12-17 5 views
1

두 개의 컨트롤 (TextField 및 Separator) 사이에 제약 조건을 추가하려고합니다. 하지만 구분 기호를 볼 수 없습니다. 이 코드에서 잘못된 점은 무엇입니까?제약 조건 누락 IOS 11 swift 4

func setupTextField() { 
    textField = UITextField(frame: CGRect(x: 0, y: 0, width: 97, height: 30)) 
    textField!.backgroundColor = .clear 
    textField!.placeholder = placeHolder 

    self.addSubview(textField!) 

    //MARK: Constraints 

    textField!.translatesAutoresizingMaskIntoConstraints = false; 
    textField!.topAnchor.constraint(equalTo: self.topAnchor).isActive = true 
    textField!.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true 
    textField!.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true 
} 

func setupSeparator() { 
    separator = UIView(frame: CGRect(x: 0, y: 32, width: 97, height: 1)) 
    separator?.backgroundColor = .lightGray 

    self.addSubview(separator!) 

    separator!.translatesAutoresizingMaskIntoConstraints = false; 
    separator!.topAnchor.constraint(equalTo: textField!.bottomAnchor, constant: 1).isActive = true 
    separator!.leftAnchor.constraint(equalTo: textField!.leftAnchor).isActive = true 
    separator!.rightAnchor.constraint(equalTo: textField!.rightAnchor).isActive = true 
} 

답변

2

당신은 당신의 분리에 높이 제약 조건을 추가해야합니다 그렇지 않으면 그것은 당신이 그것을 볼 수없는 이유 제로의 높이, 아래로 찌그러 얻을 것이다. setupSeparator 방법에 다음과 같이 추가하십시오.

separator!.heightAnchor.constraint(equalToConstant: 1).isActive = true 
관련 문제