Applying shadow to UITextView.layer?

I want to apply a shadow on a UITextView to look like a UITextField . Any idea? I use

 textView.layer.shadowOpacity=0.8; textView.layer.shadowColor=[[UIColor lightGrayColor] CGColor]; textView.layer.shadowOffset=CGSizeMake(0, 0); textView.layer.shadowRadius=3; textView.layer.cornerRadius=3; 

but at the same time, the shadow of the text is UITextView , provided that the background of the UITextView transparent. so there is an idea how to cast a shadow to a UITextView layer like this, →

enter image description here

+6
source share
2 answers
  // Add shadow [textView.layer setBackgroundColor: [[UIColor whiteColor] CGColor]]; [textView.layer setBorderColor: [[UIColor grayColor] CGColor]]; [textView.layer setBorderWidth: 1.0]; [textView.layer setCornerRadius:12.0f]; [textView.layer setMasksToBounds:NO]; textView.layer.shouldRasterize = YES; [textView.layer setShadowRadius:2.0f]; textView.layer.shadowColor = [[UIColor blackColor] CGColor]; textView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); textView.layer.shadowOpacity = 1.0f; textView.layer.shadowRadius = 1.0f; 
+9
source

The class does not indicate such a property. You will need to create it yourself. To create it using code, you have to use the QuartzCore structure. First you import it into your file, and then you can set the following properties:

 #import <QuartzCore/QuartzCore.h> textView.layer.cornerRadius = 30; textView.clipsToBounds = YES; textView.backgroundColor = [UIColor whiteColor]; 

This code assumes that you have a text view named: textView. Just change the cornerRadius to fit what you need. This makes the textView shown as shown in the picture.

+1
source

Source: https://habr.com/ru/post/909529/


All Articles