Search code examples
iosuilabelcalayer

Add CALayer to UILabel text


Is there a way to add extra CAShapeLayer( a small box) to uilalbel text. I want it to be placed exactly after the last character of label.

Thank you! some what like this. an extra layer near to the end of label


Solution

  • If you don't want to go into complexity , try unicode characters & append it in your string with some space if required. You can check in Interface builder. Select label. Go into Edit -> Emoji & Symbols & select dot .Check in attached screenshot.

    Text with unicode char

    EDIT

    Find position of last character in UILabel text & add CAShapeLayer as subview.It should work.

    OR

    You can simplify your solution by having 1 UIView with label & CAShapeLayer as subviews.Set origin of layer with label width .