Iphone 是否将阴影应用于UITextView.layer?

Iphone 是否将阴影应用于UITextView.layer?,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我想在UITextView上应用阴影,使其看起来像UITextField。你知道吗? 我正在使用 textView.layer.shadowOpacity=0.8; textView.layer.shadowColor=[[UIColor lightGrayColor] CGColor]; textView.layer.shadowOffset=CGSizeMake(0, 0); textView.layer.shadowRadius=3; textView.layer.cornerRadius

我想在
UITextView
上应用阴影,使其看起来像
UITextField
。你知道吗? 我正在使用

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;
但是如果
UITextView
背景是透明的,它会给
UITextView
的文本添加阴影。 那么,有没有办法像这样给
UITextView
层添加阴影->


该类未指定此类属性。你必须自己创造它。为了用代码创建它,您必须使用QuartzCore框架。首先将其导入文件,然后可以设置以下属性:

#import <QuartzCore/QuartzCore.h>

textView.layer.cornerRadius = 30;
textView.clipsToBounds = YES;
textView.backgroundColor = [UIColor whiteColor];
#导入
textView.layer.cornerRadius=30;
textView.clipsToBounds=是;
textView.backgroundColor=[UIColor whiteColor];

此代码假定您已将textview设置为名称:textview。只需更改拐角半径即可满足您的需要。这会使textView显示与您显示的图片相似。

尝试使用此[textView setClipsToBounds:NO];它可以工作,但我不需要它,因为textView的内容超出了范围,所以它看起来很糟糕,还有其他解决方案吗?如何做到?你的意思是在textView的背景中放一张图片吗?如果你打算在iOS 4.x上使用你的应用程序,请在textView后面放一张图片。然后您只需将textView的背景色设置为清晰的颜色我知道该解决方案,但我不想使用该方法为什么您不想这样做?我想使textView看起来像
UITextField
Hi iCode,我检查了您的代码,但如果我设置setMasksToBounds,则会出现问题:否,则文本高度大于textView高度,然后文本从textView中消失,如果我设置setMasksToBounds,则阴影消失。我可以看到您的代码的更多信息吗?您是否尝试添加textView.layer.shouldRasterize=是;这段代码为TextView控件添加了外部阴影,而不是问题的作者所指的内部阴影。我还注意到,您在代码中对相同的属性进行双重赋值,但方式不同。
    // 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;