Programmatically adding a shadow to a UIButton label

前端 未结 6 567
盖世英雄少女心
盖世英雄少女心 2021-02-04 03:15

I\'m trying to add a 1px black drop shadow to a button label with no luck. I\'ve tried this:self.setTitleShadowOffset = CGSizeMake(0, -1); but I get:

6条回答
  •  悲&欢浪女
    2021-02-04 04:14

    In Swift 3.0

    myButton.titleLabel?.layer.shadowRadius = 3
    myButton.titleLabel?.layer.shadowColor = UIColor.black.cgColor
    myButton.titleLabel?.layer.shadowOffset = CGSize(width: 0, height: 1)
    myButton.titleLabel?.layer.shadowOpacity = 0.5
    myButton.titleLabel?.layer.masksToBounds = false
    

提交回复
热议问题