How to apply text shadow to UITextView?

前端 未结 7 1072
醉梦人生
醉梦人生 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
    

提交回复
热议问题