chrisdevereux/Slash

Issue with NSBackgroundColorAttributeName ...

Closed this issue · 4 comments

Hi,

I have an issue with NSBackgroundColorAttributeName and I'm not sure if it's Slash related or an iOS 7 bug.

I have a style dictionary setup as so:

screen shot 2013-11-19 at 09 37 46

Which I then use to set the attributedText property on the textLabel of instances of UITableViewCell, which results in this:

ios simulator screen shot 19 nov 2013 09 33 36

I'd also like to change background colour. However, adding NSBackgroundColorAttributeName to the style dictionary:

screen shot 2013-11-19 at 09 38 09

(notice it's the only change)

Results in the text not being drawn at all:

ios simulator screen shot 19 nov 2013 09 35 25

Any ideas?

Looks like an iOS 7 bug: https://github.com/bradya/NSBackgroundColorAttributeName-Bug/

It seems that this bug affects UILabel, but not UITextView. I got the behaviour you described by trying your example out on UILabel, but UITextView behaved as expected. Maybe you could use UITextView instead as a workaround?

Okay, thanks @chrisdevereux, I had a feeling it would be iOS 7. I'll take a look at using UITextView.

My problem was related with the UILabel height. Using -- [myUILabel sizeToFit] -- solved the bug with NSBackgroundColorAttributeName.

I found another work around. Add an extra attribute to highlight the whole background of label to match with the either the label's background color (or the background of the view on which label is present if label is transparent), so that it merges with the background or simply use clearColor.
[attribStr addAttribute:NSBackgroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(0, attribStr.length)];
Add this code before the code portion where you are highlighting desired word or phrases.