我在獲取通知中心擴展中元素的正確對齊方面遇到困難。我希望對齊元素以遵守所應用的默認邊距 - 它應該與應用程序名稱中的第一個字符左對齊,並且與應用的某些填充對齊。如果您注意到日曆擴展程序中的行,我試圖準確地匹配這些邊距(儘管在某些情況下這些邊緣看起來不太正確)。使用自動佈局正確對齊通知中心小部件中的元素
我有我的元素設置使用自動佈局,所有都以編程方式完成。我已將領先優勢定爲self.view
的領先和尾隨self.view
的尾隨。當我在各種設備上運行擴展時,填充填充不一致,而拖尾始終對遠端清晰。
如果我將其從Leading和Trailing更改爲LeadingMargin和TrailingMargin,則看起來完全相同。如果我改變它以將元素的Leading與視圖的LeadingMargin對齊,並且跟蹤視圖的TrailingMargin,則尾隨似乎是期望的邊距,但是在iPhone 6上,儘管它在iPad上是完美的,但是在iPhone 6上領先被推得太遠。在橫屏中的iPhone 6 Plus中,領先與應用程序圖標的開頭對齊,尾部沒有填充,但有時只有!其他時候它確實增加了利潤率。
你如何配置它以正確對齊元素?
我還沒有實施widgetMarginInsetsForProposedMarginInsets
。
//viewDidLoad:
let label = UILabel()
label.backgroundColor = UIColor.blueColor()
label.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(label)
self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .Leading, relatedBy: .Equal, toItem: self.view, attribute: .Leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: label, attribute: .Trailing, relatedBy: .Equal, toItem: self.view, attribute: .Trailing, multiplier: 1, constant: 0))
let heightConstraint = NSLayoutConstraint(item: label, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1, constant: 100)
heightConstraint.priority = 999
self.view.addConstraint(heightConstraint)
iPhone 6人像:
iPhone 6加人像:
iPhone 6加上橫向:
ipad公司(縱向/橫向):
你能打印結果嗎? – 2015-03-02 07:19:05
@AshrafTawfeeq是的,請參閱新的編輯 – Joey 2015-03-07 22:35:45