I want to increase the spread of a shadow in my UILabel but I can't find the property to do that. I have added a photo below to illustrate the issue.
The top Label is the desired effect I am able to create in Photoshop. The bottom Label illustrates the properties I was able to find in iOS. Here is the code I used for the bottom Label.
let bottomLabel = UILabel(frame: CGRectMake(0, 0, maxWidth, 18))
bottomLabel.backgroundColor = UIColor.clearColor()
bottomLabel.textColor = UIColor.whiteColor()
bottomLabel.font = UIFont.boldSystemFontOfSize(16)
bottomLabel.text = title
bottomLabel.textAlignment = .Center
bottomLabel.numberOfLines = 1
bottomLabel.layer.shadowOffset = CGSize(width: 0, height: 0)
bottomLabel.layer.shadowOpacity = 1
bottomLabel.layer.shadowRadius = 2
I did find a suggestion to use a second label as a shadow but this did not give the desired result. Here is the code for that Label.
let bottomLabelShadow = UILabel(frame: CGRectMake(0, 1, maxWidth, 18))
bottomLabelShadow.backgroundColor = UIColor.clearColor()
bottomLabelShadow.textColor = UIColor.blackColor()
bottomLabelShadow.font = UIFont.boldSystemFontOfSize(16)
bottomLabelShadow.text = title
bottomLabelShadow.textAlignment = .Center
bottomLabelShadow.numberOfLines = 1
bottomLabelShadow.layer.shadowOffset = CGSize(width: 0, height: 0)
bottomLabelShadow.layer.shadowOpacity = 1
bottomLabelShadow.layer.shadowRadius = 2
It seems to work for me in a playground. You just need to increase the shadow radius to make it appear as you want it.
This is the exact playground code I used
let view = UIView(frame: CGRectMake(0,0,100,20))
view.backgroundColor = UIColor.yellowColor()
let bottomLabel = UILabel(frame: CGRectMake(0, 0, 100, 20))
bottomLabel.backgroundColor = UIColor.clearColor()
bottomLabel.textColor = UIColor.whiteColor()
bottomLabel.font = UIFont.boldSystemFontOfSize(18)
bottomLabel.text = "Testing"
bottomLabel.textAlignment = .Center
bottomLabel.numberOfLines = 1
bottomLabel.layer.shadowOffset = CGSize(width: 0, height: 0)
bottomLabel.layer.shadowOpacity = 1
bottomLabel.layer.shadowRadius = 6
view.addSubview(bottomLabel)
Or if you are using it over a blur view background, you could use vibrancy to achieve a better looking effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With