Aligning multiple sized text vertical center instead of baseline with Core Text in iOS

試著忘記壹切 提交于 2019-12-30 07:52:10

问题


Is it possible to align multiple sized text by bounding center (of each size) instead of baseline?

I tried CTRunDelegate feature, but it doesn't work. It was possible with CTRunDelegateCallbacks.getAscent and CTRunDelegateCallbacks.getDescent, but the feature doesn't work. Only CTRunDelegateCallbacks.getWidth worked. I succeed to laying out multiple sized text, images, and any objects, but only baseline-alignment supported.


回答1:


The run delegate methods getAscent and getDescent are, in fact, called (it is working in my own code). Of course, it makes sense that this doesn't change the baseline (and thus change how the text is displayed relative to other text on the line), as the ascent and descent are relative to the baseline.

It would be handy to have maybe a getBaselineOffset but, unfortunately, that doesn't exist.

My suggestion is to use the run delegate callbacks to reserve space for your differently-baselined text and then in a second pass, draw the other text with the different baseline.




回答2:


It was impossible still now. I'm regarding this is not possible for current version of Core Text.



来源:https://stackoverflow.com/questions/3904073/aligning-multiple-sized-text-vertical-center-instead-of-baseline-with-core-text

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