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:
Which I then use to set the attributedText
property on the textLabel
of instances of UITableViewCell
, which results in this:
I'd also like to change background colour. However, adding NSBackgroundColorAttributeName
to the style dictionary:
(notice it's the only change)
Results in the text not being drawn at all:
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.