私は公開しようとしているアプリに仕上げていますが、のUIButton
の背景イメージを尊重することが困難でした。私が指定したcontentMode
に関係なく、画像はちょうどcontentMode
の設定に関係なくバックグラウンドでプルーフされます。UIButtonのbackgroundImageのコンテンツモードが尊重されていません
私はこのトピックをカバーするpostを見ましたが、私の状況では何もしないようです。
これはviewDidLoad
から呼び出されます。
// I tried putting the contentMode lines here...
myButton.imageView!.contentMode = .scaleAspectFit
myButton.contentMode = .scaleAspectFit
myButton.setBackgroundImage(UIImage(named: "myImage.png"), for: .normal)
// ...and here
// myButton.imageView!.contentMode = .scaleAspectFit
// myButton.contentMode = .scaleAspectFit
// I threw this in for S's & G's to see if it would work...it didn't
myButton.translatesAutoresizingMaskIntoConstraints = false
myButton.imageView?.translatesAutoresizingMaskIntoConstraints = true
私が欠けているかわからないんだけど、私はそれは私の一部の愚かな驚くべきものになりますので安心。私はUIButton
の背景画像のcontentMode
をどのように尊重することができるかについての提案を歓迎します。読んでくれてありがとう。
更新
ボタンはカスタムボタンではなく、システムボタンとして入力されます。
これはトリックでした!ありがとうございました!!!私は今のように感じています - > https://www.youtube.com/watch?v=IS7Og1zvdy8代わりに、私は 'viewWillAppear'に入れていますので、ビューが読み込まれたときに素敵です。 – Adrian