Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying shadow to UITextView.layer?

i want to apply shadow on UITextView to give a look like UITextField.Any Idea? I am using

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 it gives shadow to the text of UITextView if the UITextView background is transparent. so is there any idea how to give shadow to layer of UITextView like this->

enter image description here

like image 790
hchouhan02 Avatar asked Feb 28 '12 09:02

hchouhan02


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;
like image 66
self Avatar answered Nov 09 '22 15:11

self


The class doesn't specify such a property. You will have to create it yourself. In order to create it with code, you will have to use the QuartzCore framework. First you import it to 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 supposes that you have your textview set up with the name: textView. Just change the cornerRadius to fit what you need. This makes the textView show like the picture you showed.

like image 37
wizH Avatar answered Nov 09 '22 17:11

wizH