IOS 5.1 UILabel with Heavy Check Mark character ignores TextColor

限于喜欢 提交于 2019-12-07 14:39:32

问题


I've been developing an iOS app and recently "upgraded" to xCode 4.3.1 and the iOS 5.1 simulator and have a very strange issue with just one character. It's called "Heavy Check Mark" in the character viewer and it looks great in my app in 5.0.1 and below and is colored with a .textColor = [UIColor redColor]. In 5.1 it shows up black in the simulator and since my phone is jailbroken I haven't checked it in 5.1 on an actual device. If I put in any other character it shows up red, but this one specific character always shows black. If I put a space before it it shows up red but the spacing is off as I'm using a layer to border. Below is actual code, but I've tried a simpler label and have the same issue.

        isChecked = [[[UILabel alloc] initWithFrame:CGRectMake(20.0,9.0,20,20)] autorelease];
        isChecked.font = [UIFont boldSystemFontOfSize:24.0];
        isChecked.backgroundColor = [UIColor clearColor];
        isChecked.textColor = [UIColor redColor];
        isChecked.layer.borderColor = [UIColor blackColor].CGColor;
        isChecked.layer.borderWidth = 2.0;
        isChecked.text = @"✔";
        isChecked.tag = 2;
        [cell.contentView addSubview:isChecked];

Anyone else experiencing problems with this or other special characters and UILabel.textColor? Any suggested workarounds? I've tried temporarily removing the layer and even creating a new minimal label and same results black if this character only and red as set if any other.


回答1:


Update and fix that works for me, but still very strange. If anyone else ran into this obscure issue I found that using a named font instead of system font seems to fix it.




回答2:


In iOS9 they have removed the possibility to colour the heavy checkmark also for non-standard fonts. This is because the U+2714 HEAVY CHECK MARK is included in Apple's set of emoji characters and it will be drawn as a full-colour bitmap instead of a single-colour unicode character.

The way to prevent this from happening, you could use a U+FE0E VARIATION SELECTOR-15 character. If you change the string to @"\u2714\uFE0E" you would be able to colour it.

isChecked.text = @"\u2714\uFE0E";
isChecked.textColor = [UIColor redColor];


来源:https://stackoverflow.com/questions/9688980/ios-5-1-uilabel-with-heavy-check-mark-character-ignores-textcolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!