1

We display a label in our apps which contains attributed text and some highlighting color. To achieve this, we use the following code which used to work:

let paddedLineAttributed = NSMutableAttributedString(string: paddedLine, attributes: [NSFontAttributeName : newFont, NSParagraphStyleAttributeName : paragraphStyle, NSBackgroundColorAttributeName : color])

But after upgrading one of our test devices to iOS 10.3, the specified background color for the label is not taking effect anymore. Instead, it was using a transparent background color making the label invisible as we are using a white text color which is the same color as the parent view.

I suspect that the NSBackgroundColorAttributeName is the culprit but the official API Reference remains unchanged - https://developer.apple.com/reference/appkit/nsbackgroundcolorattributename

Any ideas?

schystz
  • 800
  • 1
  • 8
  • 21
  • 1
    You can try this suggestion - [link](http://stackoverflow.com/questions/43074652/ios-10-3-nsstrikethroughstyleattributename-is-not-rendered-if-applied-to-a-sub) – bianca hinova Mar 29 '17 at 11:46
  • Thanks for the suggestion, will try it for now and see if that's a workaround we can do for now. – schystz Apr 03 '17 at 02:10

1 Answers1

2

Copied from @schystz comment:

Adding NSBaselineOffsetAttributeName: 0 resolves the issue.

let paddedLineAttributed = NSMutableAttributedString(string: paddedLine, attributes: [NSFontAttributeName : newFont, NSParagraphStyleAttributeName : paragraphStyle, NSBackgroundColorAttributeName : color, NSBaselineOffsetAttributeName: 0])
btype
  • 1,593
  • 19
  • 32