UILabel and UILabel's ellipsis color changes in iOS 7
Asked Answered
H

2

7

I am seeing something really strange happening on my UITableViewCells containing UILabels with ellipsis (this project is iOS 7 only). I see the ellipsis when the tableView first load. Then, if I press a cell, the text + ellipsis colors change just as I ask it to in my setHighlighted function. But as I release it (wether as I went to the details viewController and came back to the first viewController with the table view, or just pressed and then scrolled to loose the highlight), the ellipsis disappears.

In fact, I found out that it is still there, just that it is white on the white background (the color of the highlight for the text, see the code at the bottom). For a better understanding, here are screens showing what I just described :

Before clicking :

Before clicking

The cell is highlighted while we click :

The cell is highlighted

After clicking, moving to the next viewController and pressing back :

After clicking, moving to the next viewController and pressing back

Note that if I do the click + loose the highlight by scrolling, only the cell that was highlighted looses the ellipsis. Also, when scrolling the tableView, all is fine until I reach the bottom of it, and load the next elements of the list - then all ellipsis keeps the white color (and also the highlighted font, which is bold). This lead me to believe that this is caused by something done while reloading the data of the cells.

Here is the code of setHighlighted :

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    NSUInteger fontSize = _titleLabel.font.pointSize;

    [UIView animateWithDuration:(highlighted ? .2 : .5)
                          delay:0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         _background.backgroundColor = (highlighted ? [UIColor blueND] : [UIColor whiteColor]);
                         _hourLabel.textColor = (highlighted ? [UIColor whiteColor] : [UIColor blackColor]);
                         _titleLabel.textColor = (highlighted ? [UIColor whiteColor] : [UIColor blackColor]);
                         _titleLabel.font = (highlighted ? [UIFont boldSystemFontOfSize:fontSize] : [UIFont systemFontOfSize:fontSize]);
                         _consoleLabel.textColor = (highlighted ? [UIColor blueND] : [UIColor whiteColor]);
                         _consoleLabel.backgroundColor = (highlighted ? [UIColor whiteColor] : [UIColor blueND]);
                     }
                     completion:nil];
}

Does anyone have a clue as to what is happening here ?

Thank you for your help in advance !

Update : following the comment from Leo Natan, here is the result fo po _titleLabel.attributedString for the highlighted cell, once it has been highlighted, then released :

(lldb) po _titleLabel.attributedText
Mario Golf : World Tour, le Lagon Cheep Cheep en vidéo{
    NSColor = "UIDeviceWhiteColorSpace 0 1";
    NSFont = "<UICTFont: 0x1669a990> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
    NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSShadow = "NSShadow {0, -1} color = {(null)}";
}
Hecate answered 14/3, 2014 at 22:42 Comment(9)
Is the ellipsis due to word wrap? Is it added by the system or by your code? Do you use NSAttributedString somewhere in the code regarding these labels?Zane
The ellipsis is automatic, using Truncate Tail for Line Breaks and Fixed Font Size for Autoshrink in the xib file.Hecate
What about attributed strings? Could you reproduce the issue, then print in the bugger po _titleLabel.attributedText and post the output here.Zane
See my update of the question for this info. Note that the title is not an attributedString in the object it is stored in (even though I use NSAttributedStrings for other fields in my app).Hecate
Any reason why you are doing this manually? You can give a label both the normal and highlighted text and background colors, and when the cell is highlighted, it will alternate between them automatically. Could be that your animation block is confusing the CATextLayer (the label's layer).Zane
I did not use the highlighted color because for it to work, I have to set the cell as Selectable and choose a predefined cell background color between blue and gray, and thus cannot achieve the effect I'm looking for (the one in my question). I tried it again, and the ellipsis behave normally using this, but then I cannot change my title's font to make it bold when highlighted, and, as I already said, the cell's background takes one of two default color (when I want it to stay white while I change the color of another, smaller view).Hecate
Uhm, for that you have selectedBackgroundView, to give selected cells a background view with custom background color.Zane
Thanks for your ideas Leo, you helped me find a way to do it by setting highlighted text color, plus setting selectedBackgroundView to an empty white view with the frame of the cell. It is a workaround, but still better than nothing I guess ! If you want the vote, you could write a reply. If you don't, I'll just reply myself with some details, but I guess you earned it ! Thanks ;)Hecate
Added an answer, thanks.Zane
S
6

This is likely a bug with the system. Make sure to open a bug report.

As devised in the comments, instead of setting the colors manually, you can use the labels' highlightedTextColor and the cells' selectedBackgroundView to achieve what you are trying to your way.

Saratov answered 15/3, 2014 at 15:55 Comment(5)
I really think it is a bug, I'll open a bug report when I have more time tomorrow. Thanks again for your help in finding a way around it ;).Hecate
Any news on this? I've just started noticing it. Granted, one hopes the majority of users will be on iOS 8 by now, but still..Forespent
Also noticing this. Was there a radar filed?Blackmore
@Blackmore If you file a radar, please share here so I can update the answer with it.Zane
Filed 19061268 Truncation ellipses on UILabel are not changing colors correctly.Blackmore
B
0

This appears to be an apple bug. I've reported the bug (#19061268) to apple.

The current workaround I see is to set the attributed text property with the color you want instead of setting the text property.

Blackmore answered 24/11, 2014 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.