In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to solve the problem of iOS custom font display, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. What's wrong with custom fonts?
The works of designers are always ever-changing, and as programmers, we have to satisfy them in order to achieve them.
So when a designer uses a magic font, I won't say no, like this:
In order to let you see this problem better, I set a background color for label. The width and height of label are both equal to 50. Now that it looks fine in storyboard, let's Run:
Compared with the label of system font font, it is obvious that the content of this DINCondensedC font is on the upper side! Of course, you don't have to compare to find out. WTF!
two。 Solution idea
2.1 since the content is on the upper side, is it related to content Mode?
Unfortunately, changing the contentMode does not have any effect on the UILabel after an attempt (the actual drawing contains the space below).
Conclusion: it is not feasible.
2.2 inherit UILabel and rewrite drawRect? Use CoreText to draw fonts?
These two options should be feasible, but is it necessary to use such a complex [calculate font size]-[calculate offset through font size and label height]-[label unified to XXLabel] process for this small font?
If one day the designer says, "come on, let's have a rich text, with the middle words in DINCondensedC font and both sides in system font, aren't you going to cry?"
Conclusion: it is not feasible.
2.3 if the program can't solve it, then use people to solve it.
Let's find a lovely designer, invite him to have afternoon tea, have a nice dinner, take him for a big health care, and then say to him: brother, can you change the font for this UI picture? Forget it. The cost is a little high.
Conclusion: it is not feasible.
2.4 can I start with the font and modify the font myself?
Since the font is a little abnormal, we can only use a big trick: modify the font ourselves. It is said that there is an App:Glyphs that is very powerful for making / modifying fonts! Then let's download it and wait quietly. After downloading, open this [PT DIN Condensed Cyrillic.ttf] font file, but unexpectedly, this software is still charged and can only be tried for a few days. Try it, but I have to change every character in this font. As a programmer, I can't stand it!
Conclusion: it is not feasible.
3. The final solution
In the end, it depends on Apple Dad, everyone's good father. Apple offers a font modification tool: Apple Font Tool Suite. Let's use this tool to solve this thorny problem.
3.1 download the tool
Enter here, scroll to the bottom, you can see [Apple Font Tool Suite], click the download below to download a suitable Xcode version, and install it brainless after the download is complete.
3.2 get the font information file
Open the terminal and type: ftxdumperfuser-t hhea-A d PT\ DIN\ Condensed\ Cyrillic.ttf, the front [ftxdumperfuser-t hhea-A d] is the instruction, and the latter is your font file path. Finally, enter, you will see that there is an extra [DINCondensedC.hhea.xml] file in the same level folder:
3.3 modify the information in the font file
Let's open this font file and you will see:
] >
Yes, this is a XML file that contains some common information about fonts:
Ascender: the distance from the baseLine of the font to the highest point descender: the distance from the baseline of the font to the lowest point lineGap: the distance between the printing lines.
Every piece of information can be found in Apple's: hheaTable documentation. As you can see in the document, a font is also a big project. What we're going to solve today is the upper side of the [DINCondensedC] font, so let's adjust the ascender property from 700 to 900, and then save the file.
3.4 inject the modified file into the original ttf file
Open the terminal and type: ftxdumperfuser-t hhea-A f PT\ DIN\ Condensed\ Cyrillic.ttf, notice that the d after-A has been replaced by f, and enter.
3.5 replace the font file in the original project
Switch back to our project, replace the original font file, Run
The above is all the content of this article "how to solve the problem of iOS custom font display". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.