2016-07-01 7 views
1

場所の検索ボタンに制約を追加するのに苦労しています。UIMapViewにすぐに追加したいのですが、これまでの制約は機能しておらず、ボタンが一番上に止まっています左のコーナーは、ここに私のコードです: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 
} 

助けを歓迎するでしょう。

+0

locationButton.translatesAutosizingMaskIntoContraints =偽、およびlocationButton.bottomAnchor.constraint(equalTo:margins.bottomAnchor、定数:-50).isActive = trueの場合、私の問題を解決しているようです。 – user6537725

+1

あなた自身の問題に対する解決策を見つけた場合は、今後のGoogleの回答として追加してください:) –

答えて

0

設定

locationButton.translatesAutoresizingMaskIntoConstraints = false 
関連する問題