I am implementing a tag system into my app, and for this to happen I need a background image of the tag and the text to overlay that image. The problem is though – how can I stretch the image to ‘fit’ the text? ‘Maths’ works fine, but a word like ‘Economics’ would not as it would overlap the background image.
This is what my tag looks like:

You first need to calculate the expected size of text and then give frame to image accordingly.You can use the image with cap width and cap height if required. Here is the code snippet.