Line height is incorrect when using mutiple attributed strings in a custom table cell
Closed this issue · 4 comments
Hmm, could you give an example string that causes the issue, along with your expected result?
I'm assuming that in your screenshot the text should be vertically centered in the bar below the navigation bar?
Thanks for your response. I expected the label to size to the text (as it does with a static / attributed string). However, it would be great if it would just center in the bar - because I actually want some padding on the label. So adding a padding option would be a great enhancement. However, if that is complex then just making the current label center vertically would be a good fix to this problem.
Here is the code:
cell.BreakingNewsLabel.type = .Continuous
cell.BreakingNewsLabel.animationCurve = .Linear
cell.BreakingNewsLabel.animationDelay = 0.0
cell.BreakingNewsLabel.scrollDuration = 20.0
let fontAwesomeArrowString = NSMutableAttributedString(string: " " + String.fontAwesomeIconWithName(.ChevronCircleRight), attributes: [NSFontAttributeName: UIFont.fontAwesomeOfSize(20)])
let breakingNewsString = NSMutableAttributedString(string: " BREAKING NEWS: ", attributes: [NSFontAttributeName : UIFont(name: "Roboto-Medium", size: 20.0)!])
let newsExcerpt = NSString(string: CurrentOptions.getBreaking_news_excerpt()).stringByDecodingHTMLEntities()
let newsContentString = NSMutableAttributedString(string: CurrentOptions.getBreaking_news_title() + " - " + newsExcerpt, attributes: [NSFontAttributeName : UIFont(name: "Roboto-Light", size: 20.0)!])
cell.BreakingNewsLabel.backgroundColor = Constants.colorWithHexString("EA443B")
var displayString = NSMutableAttributedString()
displayString.appendAttributedString(fontAwesomeArrowString)
displayString.appendAttributedString(breakingNewsString)
displayString.appendAttributedString(newsContentString)
cell.BreakingNewsLabel.attributedText = displayString
Here is the result of a println on the display string:
{
NSFont = "<UICTFont: 0x7db06fd0> font-family: "FontAwesome"; font-weight: normal; font-style: normal; font-size: 20.00pt";
} BREAKING NEWS: {
NSFont = "<UICTFont: 0x7df4e340> font-family: "Roboto-Medium"; font-weight: normal; font-style: normal; font-size: 20.00pt";
}Here is my override title - We will keep updating the story with more information as it becomes available.
{
NSFont = "<UICTFont: 0x7db0ad60> font-family: "Roboto-Light"; font-weight: normal; font-style: normal; font-size: 20.00pt";
}
After review, I have determined that using a trim char set on the whitespace and newlinechacarter set removes the issue. So this wasn't an issue with the class itself but the string being passed in.
Ah, those kind of bugs are the worst - thanks for the follow up!