I can’t figure out how to code a drop shadow on a label. I have a score label that changes so just photoshopping text with shadows wont be possible. I need to code it so it automatically has a blurry shadow behind the text at all times. Can anyone come with some examples or help?
People saying this is a duplicate, the “duplicate” is about drop shadows on UIView, mine is about UILabel. It’s not the same thing.
7
Answers
UILabel
has a property for changing its shadow, the image below shows the property in attributes inspector and the result.Result of that effect on label
Give this a try – you can run it directly in a Playground page:
Play around with different values for the shadow Color, Opacity, Radius and Offset
Result:
You can write an extension and use it. Place the extension code outside of class ViewController.
I like subtle shadow.
On your label simply call this method
Swift 4 – Extension with shadow parameters:
On your label simply call this method
Swift 4, IBInspectable using extension
works fine but add shadow to ALL label, not to text.
in this case:
U can make a extension method for all UIView subclasses.