Wie ändere ich die Bildgröße einer Schaltfläche mit der Schaltflächenkonfiguration?IOS

Programmierung für iOS
Guest
 Wie ändere ich die Bildgröße einer Schaltfläche mit der Schaltflächenkonfiguration?

Post by Guest »

Ich verwende diesen Code, um eine Schaltfläche mit einem Bild zu erstellen. Und ich möchte, dass die Bildgröße mit der Schaltflächengröße übereinstimmt. Ich verwende dafür diesen Code:

Code: Select all

func buttonImage() {
var configuration = UIButton.Configuration.plain()
configuration.image = UIImage(named: "someImage")!
configuration.baseBackgroundColor = .red
configuration.contentInsets = .zero

let button = UIButton(configuration: configuration)
button.backgroundColor = .red
button.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(button)

button.widthAnchor.constraint(equalToConstant: 300).isActive = true
button.heightAnchor.constraint(equalToConstant: 300).isActive = true
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
aber ich habe dieses Ergebnis:
[img]https://i.sstatic.net /MPBRE3pB.png[/img]

Alles funktioniert gut, wenn ich eine Einzelskala mit 135x135 ohne @3x-Suffix anstelle von Einzelskalen mit 3 Bildern 45x45 verwende. 90x90, 135x135 in meinen Assets.
Wie kann ich das Problem mithilfe der Konfiguration beheben?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post