1

I try to display unicode character without emoji on iOS. I read this article, but when I try it on some example, the result was like:

enter image description here

I output next code:

   str1 = "\u{25B6}\u{0000FE0E} " 
   str2 = "\u{25B6} " 
   str3 = "\u{1F310}\u{0000FE0E} " 
   str4 = "\u{1F310} "

How can I fix this? I expect that it will return raw white-black unicode character.

Community
  • 1
  • 1
Vitaliy L
  • 572
  • 4
  • 20

2 Answers2

1

I can't find right solution, but for obtain grayscale image (in my case for background image for UIButton), we can draw this character and use color filter on it.

        var text = NSString(string: "\u{1F310}")
        var font = UIFont.systemFontOfSize(22)
        var size = text.sizeWithAttributes([NSFontAttributeName : font])
        UIGraphicsBeginImageContext(size)
        text.drawAtPoint(CGPointMake(0.0, 0.0), withAttributes: [NSFontAttributeName : font])
        var symbolRawImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()


        UIGraphicsBeginImageContext(symbolRawImage.size)
        var fillCtx = UIGraphicsGetCurrentContext()

        //Chose color for that sign
        textColor.setFill()
        CGContextTranslateCTM(fillCtx, 0, symbolRawImage.size.height)
        CGContextScaleCTM(fillCtx, 1.0, -1.0)
        CGContextSetBlendMode(fillCtx, kCGBlendModeNormal)
        var fillRect = CGRectMake(0, 0, symbolRawImage.size.width, symbolRawImage.size.height)
        CGContextDrawImage(fillCtx, fillRect, symbolRawImage.CGImage)
        CGContextClipToMask(fillCtx, fillRect, symbolRawImage.CGImage);
        CGContextAddRect(fillCtx, fillRect);
        CGContextDrawPath(fillCtx,kCGPathFill);
        var outputImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

So now we can choose right color.

Vitaliy L
  • 572
  • 4
  • 20
0

str1 =@"\u25c0\U0000FE0E"; works for me.

LucasKarlsson
  • 1,021
  • 1
  • 10
  • 16