iPhone UILabel text soft shadow

前端 未结 15 982
时光取名叫无心
时光取名叫无心 2020-12-07 09:31

I know soft shadows are not supported by the UILabel out of the box, on the iPhone. So what would be the best way to implement my own one?

EDIT:

15条回答
  •  广开言路
    2020-12-07 10:13

    In Swift 3, you can create an extension:

    import UIKit
    
    extension UILabel {
        func shadow() {
            self.layer.shadowColor = self.textColor.cgColor
            self.layer.shadowOffset = CGSize.zero
            self.layer.shadowRadius = 3.0
            self.layer.shadowOpacity = 0.5
            self.layer.masksToBounds = false
            self.layer.shouldRasterize = true
        }
    }
    

    and use it via:

    label.shadow()
    

提交回复
热议问题