I'm trying to make shadow size a bit bigger but I can't do it.
so far:
findAPlace.titleLabel?.layer.shadowOffset = CGSize(width: -1, height: 1)
findAPlace.titleLabel?.layer.shouldRasterize = true
findAPlace.titleLabel?.layer.shadowRadius = 1
findAPlace.titleLabel?.layer.shadowOpacity = 1
findAPlace.titleLabel?.layer.shadowColor = UIColor(red:0.07, green:0.07, blue:0.07, alpha:1.0).cgColor
how to scale shadow to be bigger than the text itself?
something like this.
Maybe with a border can be done, My text is the title of a UIButton
!!!I expect it to be all around text of the uiButton
ShadowOffset is a CGSize representing how far to offset the shadow from the path. The default value of this property is (0.0, -3.0).
You can do in this way
Actually You need to use setTitleShadowColor
instead of titleLabel?.layer.shadowColor
Here is full working code
let btnTemp = UIButton(type: .custom)
btnTemp.frame = CGRect(x: 50, y: 200, width: 150, height: 40)
btnTemp.setTitle("Hello", for: .normal)
btnTemp.titleLabel?.layer.shouldRasterize = true
btnTemp.titleLabel?.layer.shadowRadius = 1.0
btnTemp.titleLabel?.layer.shadowOpacity = 1.0
btnTemp.setTitleColor(UIColor.blue, for: .normal)
btnTemp.backgroundColor = UIColor.gray
btnTemp.titleLabel?.shadowOffset = CGSize(width: -1, height: 1)
btnTemp.setTitleShadowColor(UIColor(red:0.07, green:0.07, blue:0.07, alpha:1.0), for: .normal)
self.view.addSubview(btnTemp)
Hope it helps
Output:
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