How to apply text shadow to UITextView?

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

    In iOS 6+ use attributed text

    NSShadow * shadow = [[NSShadow alloc] init];
    shadow.shadowColor = [UIColor blackColor];
    shadow.shadowOffset = CGSizeMake(2, 2);
    
    NSDictionary * textAttributes =
    @{ NSForegroundColorAttributeName : [UIColor blueColor],
       NSShadowAttributeName          : shadow,
       NSFontAttributeName            : [UIFont boldSystemFontOfSize:20] };
    
    textView.attributedText = [[NSAttributedString alloc] initWithString:@"Hello" 
                                                              attributes:textAttributes];
    

    Hello example

提交回复
热议问题