开发者

Adding drop shadow to UIWebView and UITextView

开发者 https://www.devze.com 2022-12-25 23:11 出处:网络
I have a UITextView and a WebView side by side and I woul开发者_StackOverflow社区d like to add a drop shadow to both. This is an iPad app, so they rotate, thus an ImageView under them probably would n

I have a UITextView and a WebView side by side and I woul开发者_StackOverflow社区d like to add a drop shadow to both. This is an iPad app, so they rotate, thus an ImageView under them probably would not work. Any ideas?


UIViews have CALayers, that have some built-in shadow support. Try these properties out:

view.layer.shadowColor
view.layer.shadowOffset
view.layer.shadowOpacity
view.layer.shadowRadius

That may get you what you need pretty quickly. You might need to #import <QuartzCore/QuartzCore.h> to get the compiler to understand what's going on.


the solution would be like

[myTextBox.layer setShadowColor:[[UIColor blackColor] CGColor]];
[myTextBox.layer setShadowOffset:CGSizeMake(1.0, 1.0)];
[myTextBox.layer setShadowOpacity:1.0];
[myTextBox.layer setShadowRadius:0.3];

but this just works for OS 3.2 and up.


Here is swift version:

func applyDropShadow() {
    textView.layer.shadowColor = UIColor.blackColor().CGColor
    textView.layer.shadowOffset = CGSizeMake(3, 3)
    textView.layer.shadowOpacity = 0.7
    textView.layer.shadowRadius = 8.0
    textView.clipsToBounds = false

}


I would add a view that sits behind the text field, and apply the shadow effects to that. This way the shadow does not move with the content.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号