0
신속하게 작성된 iOS 응용 프로그램의 단추보기 개체를 내 장면에 프로그래밍 방식으로 추가하려고합니다. 여기에 대한 답변을 따르려고합니다. https://stackoverflow.com/a/36263784신속하게 제약 조건을 올바르게 활성화하는 방법
그러나 장면의 버튼을 볼 수 없습니다. 내 viewDidLoad 메서드에서이 메서드를 호출합니다.
func buildLoginButton() -> UIButton
{
let button = UIButton()
button.backgroundColor = .greenColor()
button.setTitle("Test Button", forState: .Normal)
self.view.addSubview(button)
let c1 = NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
let c2 = NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)
button.widthAnchor.constraintEqualToAnchor(nil, constant: 200).active = true
button.heightAnchor.constraintEqualToAnchor(nil, constant: 100).active = true
NSLayoutConstraint.activateConstraints([c1, c2])
view.bringSubviewToFront(button)
return button
}
디버그 창에서 모호한 레이아웃 제약과 관련하여 경고 메시지가 표시됩니까? – ozgur
'buildLoginButton()'이 호출되도록 보장 했습니까? 메인 스레드에서? – BaseZen