Question

I am trying to display words with spanish letter Ñ but the letter only appears without the diacritical tilde as capital N. However, the small letter ñ is being displayed properly. Any idea how to display the letter in CATextLayer with default font in iOS?

I have given the sample code below.

 CATextLayer *tempLayerForTextWith = [CATextLayer layer];
    tempLayerForTextWith.frame = CGRectMake(10, 10, 100, 100);
    //tempLayerForTextWith.font = [[UIFont boldSystemFontOfSize:actualFontSize] fontName];
    //tempLayerForTextWith.fontSize = actualFontSize;
    tempLayerForTextWith.string = @"ñÑ";
    tempLayerForTextWith.backgroundColor = [[UIColor lightGrayColor] CGColor];
    wordLayer.foregroundColor = textColor;
    [contentView.layer addSublayer:tempLayerForTextWith];

I have the same issue for german letters Ä, Ö, Ü. Please advice how to resolve if you are aware.

Update after Brad's question.

I found out that only the first line is having this issue. If I set the text to long text so that it wraps using the code below, then I find that the 2nd line onwards the diacritics are drawn properly. Is there a way in CATextLayer to specify the baseline for the text as it seems that the baseline set by iOS such that the head of the text is being cut off.

tempLayerForTextWith.string = @"ÑñÑÄÖÜÑñÑÄÖÜÑñÑÄÖÜÑñÑÄÖÜÑñÑÄÖÜ"; tempLayerForTextWith.wrapped = YES;

Was it helpful?

Solution

Its a bug in iOS. Its been logged and Apple accepted. You can either add a new line character to introduce a new line and it will show the diacritics properly in second line or you can use drawLayer in CALAyer or other option to draw yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top