2017-04-22 50 views
0

我有一個UITableViewCell有三個標籤:對齊的UILabel與NSSuperscriptAttributeName和自動佈局

enter image description here

UILabel使用其attributedString屬性添加上下標對化學式的權利。我使用PureLayout設置所有自動佈局的限制,並添加了相同的約束的前兩名標籤管理對上海華頂(contentView)的距離:

[label autoPinEdgeToSuperviewEdge: ALEdgeTop withInset: 8.0f]; 

我也使用約束來設置底部標籤頂部與左側標籤底部之間的距離。

但是,正如您所看到的,它們與頂部沒有相同的距離,並且它們沒有水平對齊。我猜這是因爲超級和/或下標屬性。

我也試着調整其水平軸:

[rightLabel autoAlignAxis: ALAxisHorizontal toSameAxisOfView: leftLabel]; 

但與相同的結果。

任何建議如何使這項工作?

編輯:這似乎與此錯誤有關:iOS 10.3: NSStrikethroughStyleAttributeName is not rendered if applied to a sub range of NSMutableAttributedString,並且只發生在iOS 10.3中。如果我從這個問題中增加接受的答案,那麼這種聯繫就像預期的那樣。

編輯:這些都是正確的標籤屬性:

CH{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc2515a10> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 17.00pt"; 
}3{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc27577e0> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 12.75pt"; 
    NSSuperScript = "-1"; 
}CH{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc2515a10> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 17.00pt"; 
}2{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc27577e0> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 12.75pt"; 
    NSSuperScript = "-1"; 
}OH{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc2515a10> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 17.00pt"; 
}+{ 
    NSBaselineOffset = 1; 
    NSFont = "<UICTFont: 0x7fcdc27577e0> font-family: \"Avenir-Medium\"; font-weight: normal; font-style: normal; font-size: 12.75pt"; 
    NSSuperScript = 1; 
} 

回答

0

你可以嘗試使用UIStackview與對齊= .center 兩個頂級品牌,或只是腳右標籤相匹配的插圖。 排版是hard

+0

我會試一試,謝謝指出。 – Koen