简体   繁体   中英

How Can I Apply a CIFilter to Part of a UILabel (or Produce the Same Visual Effect)

I need to alter specific substrings in a UILabel, using a CIFilter. A simple example might look like this:

在此处输入图片说明

Is there a way to access and modify (ie, use a CIFilter on) individual UILabel glyphs? Or will I need to simulate this effect by pasting together multiple one-or-more-glyph labels?

Clever answers are always appreciated.

I provided an answer for similar UILabel CIFilter type processing here:

Make emoji symbols grayscale in UILabel

There they wanted the entire label greyscale, but you could substitute the CIFilter and use the Blur Filter to blur the entire label.

Depending on how your view is laid out, you may want to break out the text before the blurred area into a separate UILabel, then the blurred UILabel, and lastly the text after the blur in a UILabel. Put them all in a UIStackView and then apply the blur only to the center label?

That may be less than ideal though depending on what you are trying to do. So the alternative is to use the code in my other answer as a starting point and then do something like this:

  1. Find the x offset for where the character is that you want to start the blur.
  2. Do the same for the last character.
  3. When you apply the CIFilter, use a mask for just the region where you want the blur applied.

That is how I would chase this down, if the UIStackView approach doesn't work for you. I hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM