私は単純な垂直UIStackView
を持ち、3番目のサブビューでプログラムで作成したいUIButton
を配置します。私はこれを行うことができますが、ボタンは、私のコードで設定しているサイズではなく、サブビューの全幅と高さに拡大しています。ストーリーボードを使用してUIStackView
を作成しましたが、このボタンをプログラムで追加するので、ボタンの外観をよりよく制御できます。 AppleのドキュメントでUIStackViewに配置されたプログラムで作成されたUIButtonに制約を追加するには
let doThisButton = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 40))
doThisButton.setTitle("Let's do this.", forState: .Normal)
doThisButton.setTitleShadowColor(UIColor.blackColor(), forState: .Highlighted)
doThisButton.translatesAutoresizingMaskIntoConstraints = false
doThisButton.layer.cornerRadius = 3
doThisButton.layer.backgroundColor = UIColor(hexString: "b7b7b7").CGColor
doThisButton.layer.borderWidth = 0
liftLogStackView.addArrangedSubview(doThisButton)
、私はそれがうまくいくかもしれないが、今、私はそうは思わないように思えたUILayoutGuide
を見つけました。私はこれを試しました:
let container = UILayoutGuide()
doThisButton.addLayoutGuide(container)
doThisButton.leadingAnchor.constraintEqualToAnchor(container.leadingAnchor, constant: 8.0).active = true
doThisButton.trailingAnchor.constraintEqualToAnchor(container.trailingAnchor, constant: 8.0).active = true
liftLogStackView.addArrangedSubview(doThisButton)
container.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor).active = true
そしてそれは違いました。
SOの検索の多くは、私の問題に固有の答えを出さなかったので、誰かが助けてくれることを望んでいます。前もって感謝します。
感謝を。私はちょうどあなたがこの新しい質問を見てみる機会を持っている場合、この事でもう一つの問題があります([リンク](http://stackoverflow.com/questions/40393659/why-is-uiimageview- content-mode-ignore))、本当に感謝しています。 – Jim