使用QuartzCore为UITextView创建阴影 [英] Create shadow using QuartzCore for UITextView

查看:114
本文介绍了使用QuartzCore为UITextView创建阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码使用 QuartzCore 为我的 UITextView 创建了一个阴影。

I have created a shadow using QuartzCore for my UITextView with this following code.

myTextView.layer.masksToBounds = NO;
myTextView.layer.shadowColor = [UIColor blackColor].CGColor;
myTextView.layer.shadowOpacity = 0.7f;
myTextView.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
myTextView.layer.shadowRadius = 8.0f;
myTextView.layer.shouldRasterize = YES;

它创建一个阴影看起来也不错。这是我上面代码的输出。

It creates a shadow and looks good too. Here it is my output for the above code.

但是当我尝试向添加文本时myTextView ,我的textView文本超出界限,它看起来像 myTextView 之外的那样。

But When I try to add a text to the myTextView, my textView text goes out of the bounds and it looks outside of the myTextView like below.

只有在我添加阴影时才会发生这种情况。 textView 里面的文字没有显示怪异如果我不添加阴影。我做错了什么?我怎么能克服这个?为什么会这样?

It's happening only when I add shadow. The text inside the textView is not showing weird If I don't add shadow.What I am doing wrong?? How could I overcome this? Why it is happening?

更新:

@borrrden
我发现它正在发生,因为设置 maskToBounds = NO; 如果我们设置然后我们无法获得影子。原因这是一个答案

@borrrden said I found It is happening, because of setting the maskToBounds = NO; If we set YES then we cannot get shadow. Reason Here it is an answer

推荐答案

由于UIView行为,没有正确的解决方案。当masksToBounds为NO时,任何延伸到图层边界外的子图层都将可见。并且UITextField在UITextField图层外滚动文本。

There is no "right" solution, because of UIView behavior. When masksToBounds is NO, any sublayers that extend outside the layer's boundaries will be visible. And UITextField scroll text outside the UITextField layer.

在UITextView后添加清晰视图并在其上放一个阴影。

Add clear view behind the UITextView and drop a shadow on it.

这篇关于使用QuartzCore为UITextView创建阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆