2017-02-19 1 views
2

두 개의 UIView, UILabelUITextField이 있는데 첫 번째 것은 필드의 제목이고 두 번째는 정보가 입력되는 곳입니다. (emailLabel22 불리는)를 위해 그 UILabel의UILabel의 너비가 프로그래밍 된 자동 레이아웃을 사용하는 텍스트를 초과 함

//Constraints: 
    inputField.translatesAutoresizingMaskIntoConstraints = false; 
    //Setting trailing = superview(which is called self)'s trailing +2.0 
    NSLayoutConstraint(item: inputField, 
    attribute: .trailing, relatedBy: .equal, 
    toItem: self, attribute: .trailingMargin, 
    multiplier: 1.0, constant: 2.0).isActive = true; 

    //Set Top = superview(which is called self) top -2.0 
    NSLayoutConstraint(item: inputField, 
    attribute: .top, relatedBy: .equal, 
    toItem: self, attribute: .topMargin, 
    multiplier: 1.0, constant: -2.0).isActive = true; 

    //Setting the height = 30 
    NSLayoutConstraint(item: inputField, attribute: .height, 
    relatedBy: .equal, 
    toItem: nil, attribute: .notAnAttribute, 
    multiplier: 1.0, constant: 30).isActive = true; 

: 입력 필드의

그들의 자동 레이아웃 제약을 설정 해요

//Constraints: 
    //  Left 
    NSLayoutConstraint(item: emailLabel22, 
    attribute: .leading, relatedBy: .equal, 
    toItem: self, attribute: .leadingMargin, 
    multiplier: 1.0, constant: 2.0).isActive = true; 

    //  Buffer Right 
    NSLayoutConstraint(item: emailLabel22, 
    attribute: .trailing, relatedBy: .equal, 
    toItem: inputField, attribute: .leading, 
    multiplier: 1.0, constant: -8.0).isActive = true; 

    //  Align Tops 
    NSLayoutConstraint(item: emailLabel22, 
    attribute: .top, relatedBy: .equal, 
    toItem: inputField, attribute: .top, 
    multiplier: 1.0, constant: 0).isActive = true; 

    //  Height 
    NSLayoutConstraint(item: emailLabel22, 
    attribute: .height, relatedBy: .equal, 
    toItem: nil, attribute: .notAnAttribute, 
    multiplier: 1.0, constant: 30).isActive = true; 

    //  Buffer Right -- **For Input Field** 
    NSLayoutConstraint(item: inputField, 
    attribute: .leading, relatedBy: .equal, 
    toItem: emailLabel22, attribute: .trailing, 
    multiplier: 1.0, constant: 8.0).isActive = true; 

    //  Locking in Width??? (Should I use this?) 
    NSLayoutConstraint(item: emailLabel22, 
    attribute: .width, relatedBy: .equal, 
    toItem: nil, attribute: .notAnAttribute, 
    multiplier: 1.0, constant: emailLabel22.frame.size.width); 
,위 코드의 요지는 다음과 같습니다. inputField는 수퍼 뷰 ( self)에 오른쪽 정렬됩니다. 이메일은 왼쪽 정렬됩니다. 그런 다음 미학을 위해 그들 사이에 간격이 있습니다. 내가 emailLabel22 먼저 설정하면 다음이 폭이 큰되고 입력 필드가 그들 사이에 많은 빈 공간 화면의 오른쪽에 몰려있어,

:

문제입니다. Like so.

위의 코드에서와 같이 입력 필드를 먼저 설정하면 전자 메일은 잠긴 너비 인 73이됩니다. 즉, 73pt 너비에 맞지 않는 텍스트 줄임표로 잘립니다. Like So

전자 메일의 너비를 제한하면 텍스트 필드에 맞지 않는 단어를 입력하면 inputField의 크기가 확장됩니다. Like So

이것은 실제로 문제가되지 않지만 강력한 라벨/텍스트 필드 콤보를 작성하여 텍스트를 설정하고 완벽하게 맞출 수 있으므로 꼭 갖고 싶지 않습니다. 이메일 레이블의 "너비 줄이기". 나는 그것이 원하는만큼 많이 확장되기를 원하지만 텍스트 크기 내에서하고 싶습니다. 또한 inputField가 전자 메일 레이블을 무너 뜨리는 것을 원하지 않습니다. 나는 또한 전자 메일의 글꼴 크기를 줄이고 싶지 않습니다. 입력을 줄이는 것이 좋습니다.

나는 이것을 3 시간 동안 고치려고 노력해 왔습니다. 나는 어떻게해야할지 모른다.

감사합니다.

+1

그것은 내가 도울 수있는 시간이 없어 지금에있어 늦은 밤,하지만 애플은 실제로 좋은 문서를 가지고 https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/ViewswithIntrinsicContentSize.html – dfd

답변

2

시도 세트 포옹과 commpresion 저항 우선 순위 당신의 UILabel의에와의 UITextField

enter image description here

+0

그 사용법을 알지 못했습니다. 이제 알았어 !! 고마워요. ( – QuantumHoneybees

+0

컴퓨터도 항상이 이미지를 가지고 있기 때문에 기억하지 못합니다. –

+0

이 이미지를 어디에서 가져 왔는지 공유하고 싶습니까? 좋아해요. – QuantumHoneybees