Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Shadow - iOS, swift 3.0

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.

example

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

like image 530
Dpetrov Avatar asked May 30 '17 08:05

Dpetrov


People also ask

What is shadowOffset?

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).


1 Answers

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:

enter image description here

like image 90
Janmenjaya Avatar answered Sep 28 '22 01:09

Janmenjaya