1
Ich habe Schwierigkeiten, hinzufügen, um eine Location Finder-Schaltfläche, die ich hinzufügen möchte zu einem UIMapView in Swift hinzufügen, bis jetzt scheint keiner meiner Einschränkungen funktionieren und der Button ist in der oberen stecken linke Ecke, hier ist mein Code:Hinzufügen von Einschränkungen zu einer Schaltfläche programmgesteuert mit Swift
override func loadView()
{
mapView = MKMapView()
view = mapView
let margins = view.layoutMarginsGuide
let locationButton = UIButton()
mapView.addSubview(locationButton)
locationButton.setTitle("find location", for: [])
locationButton.backgroundColor = UIColor.lightGray().withAlphaComponent(0.6)
locationButton.layer.cornerRadius = 3
locationButton.sizeToFit()
locationButton.translatesAutoresizingMaskIntoConstraints = true
locationButton.bottomAnchor.constraint(equalTo: margins.bottomAnchor, constant: 20).isActive = true
locationButton.leadingAnchor.constraint(equalTo: margins.leadingAnchor).isActive = true
locationButton.trailingAnchor.constraint(equalTo: margins.trailingAnchor).isActive = true
}
jede Hilfe wird herzlichst geschätzt.
locationButton.translatesAutosizingMaskIntoContraints = false, und locationButton.bottomAnchor.constraint (EqualTo: margins.bottomAnchor, konstant: -50) .isActive = true, scheint mein Problem gelöst zu haben. – user6537725
Wenn Sie die Lösung für Ihr Problem gefunden haben, fügen Sie es als Antwort für zukünftige Google-Mitarbeiter hinzu :) –