1
私はお互いの下に2つのラベルを持つカスタムビューを持っています。私は次の制約を使用して、ロケーションビュー内のラベルを配置するためのiOSカスタムビュー - CGRect.zeroを持つinit - 制約の警告
self.gMapsView.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "H:|-[locationView]-|",
options: NSLayoutFormatOptions(rawValue: UInt(0)),
metrics: nil,
views: views
)
)
self.gMapsView.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "V:[locationView]-(paddingBottom)-|",
options: NSLayoutFormatOptions(rawValue: UInt(0)),
metrics: [
"paddingBottom": LOCATION_VIEW_CONFIG.paddingBottom
],
views: views
)
)
:ビューのinitメソッドは、メインビュー内のサブビューを配置するために、この
self.locationView = LocationView(frame: CGRect.zero)
のように見える、私は次の制約を使用します。
self.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "H:|[streetLabel]|",
options: NSLayoutFormatOptions(rawValue: UInt(0)),
metrics: nil,
views: views
)
)
self.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "H:|[cityLabel]|",
options: NSLayoutFormatOptions(rawValue: UInt(0)),
metrics: nil,
views: views
)
)
self.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "V:|-[streetLabel]-[cityLabel]-|",
options: NSLayoutFormatOptions(rawValue: UInt(0)),
metrics: nil,
views: views
)
)
残念ながら私は、制約の警告を取得しています:
(
"<NSAutoresizingMaskLayoutConstraint:0x608000280820 h=--& v=--& Test.LocationView:0x7fdc40f0c780.height == 0 (active)>",
"<NSLayoutConstraint:0x608000280190 UILabel:0x7fdc40f0cb40.top == Test.LocationView:0x7fdc40f0c780.topMargin (active)>",
"<NSLayoutConstraint:0x608000280320 V:[UILabel:0x7fdc40f0cb40]-(NSSpace(8))-[UILabel:0x7fdc40d155e0] (active)>",
"<NSLayoutConstraint:0x6080002802d0 Test.LocationView:0x7fdc40f0c780.bottomMargin == UILabel:0x7fdc40d155e0.bottom (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000280320 V:[UILabel:0x7fdc40f0cb40]-(NSSpace(8))-[UILabel:0x7fdc40d155e0] (active)>
どうすれば修正できますか?ありがとうございます:)
ありがとうございます!私はすでにそのコードを持っていましたが、親ビューにビューを追加した後に呼びました。 – user3532505