0
我有一個視圖用作表視圖中某個部分的標題。它包含一個應該與可讀內容指南對齊的標籤。適用於iPad,但在電話上:完全不縮進。UILabel與可讀指南對齊在iPad上工作,但不在電話上
let v = UIView(frame: .zero)
let label = UILabel(frame: .zero)
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
let attrText = NSMutableAttributedString(...
attrText.addAttributes(titleLabelAttributes, range: NSMakeRange(0, attrText.length))
label.attributedText = attrText
label.font = UIFont.preferredFont(forTextStyle: .headline)
v.addSubview(label)
let readableGuide = v.readableContentGuide
readableGuide.topAnchor.constraint(equalTo: label.topAnchor).isActive = true
readableGuide.leadingAnchor.constraint(equalTo: label.leadingAnchor, constant:0.0).isActive = true
readableGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor, constant:0.0).isActive = true
爲什麼會這樣?
我從閱讀一篇文章中得到了這個,你能否嘗試註釋掉'readableGuide.topAnchor.constraint(equalTo:label.topAnchor).isActive = true'並添加它? 'label.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor)' – Glenn
沒有什麼區別,但是謝謝。 – johnnyMac