How can I get the CIAttributedTextGenerator filter to break onto multiple lines?

50 Views Asked by At

I'm working on an app that overlays text onto an image. We want to be able to constrain the width of the text and have it break onto multiple lines, much in the same way that UILabel does when we set numberOfLines = 0. In my mind, this should be possible by constraining the extent that the filter has to work within somehow, or by chaining it with a clamp (since the output bitmap is generated lazily.) Unfortunately, nothing I've run into seems to do the trick:

  • The CIClamp approach generates a nil outputImage when provided a CIVector(cgRect:) argument
  • There doesn't seem to be a way to specify a CIFilterShape to draw the text within when using the bundled filters
  • You can provide a CIFilterShape when invoking CIKernel.apply but a) I don't have a custom CIKernel (and am hoping not to write one) and b) I don't have a way to extract the kernel from the CIAttributedTextGenerator filter

I'm resigning myself to manually computing line breaks but it really seems like Core Image ought to be able to handle this use case. Am I just missing something?

0

There are 0 best solutions below