使用NSAttributedString删除上限 [英] Drop cap with NSAttributedString

查看:175
本文介绍了使用NSAttributedString删除上限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 referencedText UILabel 中做一个首字下沉字符> NSAttributedString 仅限属性。像这样:

I would like to do a drop cap first character in a UILabel using the attributedText NSAttributedString property only. Like this:

http: //www.interpretationbydesign.com/wp-content/uploads/2009/02/drop_caps.gif

我已经尝试调整基线第一个字符的范围为负值,它用于将第一个字符的顶部与第一个字符的其余部分的顶部对齐。但是我还没有找到任何方法让其他行流到下限字符的右边。

I have experimented with adjusting the base line for the range of the first character to a negative value, and it works for aligning the top of the first char with the top of the rest of the first line. But I have not found any way to make the other lines flow to the right of the drop capped character.

这可以使用 NSAttributedString来解决,还是我必须拆分字符串并使用Core Text自行渲染?

Can this be solved using NSAttributedString only, or do I have to split the string and render it myself using Core Text?

推荐答案

CoreText不能做掉帽,因为它由字形组成的线组成。一个下降盖将覆盖不支持的多行。

CoreText cannot do drop caps because it consists of lines made up of glyph runs. A drop cap would cover multiple lines which is not supported.

要实现此效果,您必须单独绘制上限,然后在路径中绘制其余文本围绕着它。

To achieve this effect you would have to draw the cap separately and then draw the rest of the text in a path that goes around it.

长话短说:在UILabel中是不可能的,但是在CoreText上做了一些工作。

Long story short: not possible in UILabel, possible, but a fair bit of work with CoreText.

使用CoreText执行此操作的步骤如下:

The steps to do it with CoreText are:


  • 为单个字符创建框架设置。

  • 得到它的界限

  • 创建一个可以省去掉落框架的路径

  • 为其余字符创建一个框架集此路径

  • 绘制第一个字形

  • 绘制休息

  • create a framesetter for the single character.
  • get its bounds
  • create a path that spares out the frame of the drop cap
  • create a framesetter for the remaining characters with this path
  • draw first glyph
  • draw rest

这篇关于使用NSAttributedString删除上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆