How to apply text shadow to UITextView?

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

    The answer with

    text.layer.shadowColor

    adds shadow to whole textView, perhaps it works, but it adds shadow not only to text.

    The correct answer is:

    CALayer *textLayer = ((CALayer *)[textView.layer.sublayers objectAtIndex:0]);
    textLayer.shadowColor = [UIColor whiteColor].CGColor;
    textLayer.shadowOffset = CGSizeMake(0.0f, 1.0f);
    textLayer.shadowOpacity = 1.0f;
    textLayer.shadowRadius = 1.0f;
    

提交回复
热议问题