iosarraysswiftchinese-localechinese-simplified

Render Chinese characters correctly in iOS


I have certain Chinese text in my app that I want to make sure appears in regular script. It currently renders like this on the phone:

enter image description here

However, I want it to render like this so that it looks more natural:

enter image description here

I've tried setting the font on my Text component.

Text(text)
   .font(.custom("STHeiti", size: 24))

Regardless, it shows up as intended on the computer (i.e. in the SwiftUI preview section). But I cannot get it to render as intended on the phone.

This post explains the issue generically, but I haven't been able to find a fix.

iOS version 17.5


Solution

  • As you may know, this is merely a font difference. The system font chooses which font to use depending on the language & region settings. If you set your phone's region to mainland China and language to Simplified Chinese, you should see the correct form. The undesirable form of 包 you see is the standard form for Japan.

    Compare the images from zdic.net,

    enter image description here enter image description here

    If you want it to appear the same for all users regardless of their language & region settings, you can set the font explicitly like in your attempt. As far as I know, the default font for simplified Chinese since iOS 9 is "PingFang SC", not "STheiti".

    .font(.custom("PingFang SC", size: 24))