2017-11-24 9 views
1

내 프로젝트에서 UITextField 및 UIButton을 기반으로하는 몇 가지 사용자 정의 클래스 파일이 있습니다. 예를 들어 xcode Interface Builder가 IBDesignable 클래스를 업데이트하지 않습니다.

는, UITextField 클래스는 다음과 같습니다 IB 나를 보여주고 무엇을 다음 SimScreenshot

은 다음과 같습니다 : 여기

import UIKit 

@IBDesignable class RoundedTextField: UITextField { 

    override func awakeFromNib() { 
     super.awakeFromNib() 

     layer.cornerRadius = 25 
     layer.borderWidth = 2 
     layer.borderColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) 
     clipsToBounds = true 
     textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) 

     // Placeholder colour 
     attributedPlaceholder = NSAttributedString(string: placeholder!, attributes: [NSAttributedStringKey.foregroundColor: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)]) 
    } 

    // Placeholder text indent 
    override func textRect(forBounds bounds: CGRect) -> CGRect { 
     return bounds.insetBy(dx: 20, dy: 5) 
    } 

    // Editing text indent 
    override func editingRect(forBounds bounds: CGRect) -> CGRect { 
     return bounds.insetBy(dx: 20, dy: 5) 
    } 
} 

시뮬레이터 나 표시되는지 정확한 버전입니다 IBScreenshot

제 IB 스크린 샷에서 볼 수 있듯이, 업데이트되는 유일한 요소는 자리 표시 자 텍스트의 들여 쓰기입니다. 나머지 사용자 설정은 업데이트되지 않습니다.

의견이 있으십니까?

p.s. 요소를 선택하면 ID 관리자에서 'Designables'필드가 '최신 정보'입니다.

Xcode를 정리하고 다시 시작하려고했습니다.

감사합니다. Scott

+0

검사도 prepareForInterfaceBuilder()이 호출이 대답 https://stackoverflow.com/questions/45408409/weird-issue-while-using-ibdesignable-uilabel-class/45408532#45408532 또는이 하나 HTTPS : //stackoverflow.com/questions/44533610/ios-cannot-get-an-ibdesignable-xib-file-to-show-up-on-storyboard-or-simulato/44547101#44547101 –

+1

감사합니다 Reinier, 나는 두 번째를 사용했습니다. 링크 및 문제를 해결하기위한 다른 소스. – scottc00

답변

0

나는 Reinier의 2 번째 링크에서 도움을 받아 문제를 해결했으며 이전에 Udemy를 ​​취했다.

setupView() 함수로 사용자 정의를 구현했습니다. 내가 awakeFromNib()

import UIKit 

@IBDesignable class RoundedTextField: UITextField { 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     setupView() 
    } 

    override func prepareForInterfaceBuilder() { 
     super.prepareForInterfaceBuilder() 
     self.setupView() 
    } 

    // Placeholder text indent 
    override func textRect(forBounds bounds: CGRect) -> CGRect { 
     return bounds.insetBy(dx: 20, dy: 5) 
    } 

    // Editing text indent 
    override func editingRect(forBounds bounds: CGRect) -> CGRect { 
     return bounds.insetBy(dx: 20, dy: 5) 
    } 

    func setupView() { 
     layer.cornerRadius = 25 
     layer.borderWidth = 2 
     layer.borderColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) 
     clipsToBounds = true 
     textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) 

     // Placeholder colour 
     attributedPlaceholder = NSAttributedString(string: placeholder!, attributes: [NSAttributedStringKey.foregroundColor: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)]) 
    } 
}