I need to embed small icons ( sort of custom bullets ) to my UILabel
in iOS7.
How can I do this in interface designer? Or at least in code?
In Android there are leftDrawable
and rightDrawable
for labels, but how it is done in iOS?
Sample in android :
Swift 3 UILabel extention
Tip: If you need some space between the image and the text just use a space or two before the labelText.
I've made an implementation of this feature in swift here: https://github.com/anatoliyv/SMIconLabel
Code is as simple as it's possible:
Here is how it looks:
Swift 3 version
Swift 4.2:
You can use this function to add images or small icons to the label
In Swift 2.0,
My solution to the problem is a combination of a couple of answers on this question. The problem I faced in @Phil's answer was that I couldn't change the position of the icon, and it always appeared in right the corner. And the one answer from @anatoliy_v, I couldn't resize the icon size I want to append to the string.
To make it work for me, I first did a
pod 'SMIconLabel'
and then created this function:This solution will not only help you place the image but will also allow you to make necessary changes to the icon size and other attributes.
Thank You.