How to apply text shadow to UITextView?

前端 未结 7 1058
醉梦人生
醉梦人生 2021-02-06 21:12

Actually I love UILabel. They\'re sweet. Now I had to go to UITextView because UILabel is not aligning text vertically to the top. Damn. O

相关标签:
7条回答
  • 2021-02-06 21:58

    Swift 3


    let textView = UITextView(frame: view.frame)
    textView.font = UIFont(name: "Helvetica", size: 64.0)
    textView.textColor = .red
    textView.text = "Hello World"
    
    textView.layer.shadowColor = UIColor.black.cgColor
    textView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
    textView.layer.shadowOpacity = 1.0
    textView.layer.shadowRadius = 2.0
    textView.layer.backgroundColor = UIColor.clear.cgColor
    

    Swift 2.3


    let textView = UITextView(frame: view.frame)
    textView.font = UIFont(name: "Helvetica", size: 64.0)
    textView.textColor = UIColor.redColor()
    textView.text = "Hello World"    
    
    textView.layer.shadowColor = UIColor.blackColor().CGColor
    textView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
    textView.layer.shadowOpacity = 1.0
    textView.layer.shadowRadius = 2.0
    textView.layer.backgroundColor = UIColor.clearColor().CGColor
    
    0 讨论(0)
提交回复
热议问题