Search code examples
iostransformnsattributedstringcore-text

Flip characters separately in string


I have a special requirement in my IOS app, I want to flip every characters in a string, the following picture is the input and final result I want.

enter image description here

Currently I have tried with UIFont, I use setTransform method, but this applies to the context which flip the entire string. Then I try to use NSAttributedString since it can apply special effect to a given range in the text. I go through all the attributes in this page under Constants section, but it seems there is no such attribute.

Is that possible to create context for each character in a string? How can I manage the spaces between characters if this is true?


Solution

  • You could reverse the string and then flip it.

    I.e.

    ABCD -> DCBA -> the flipped image you want.

    Just use the transform like you did before but reverse the string first.