UIView inside UIView with Shadow?

Posted by Rnegi on Stack Overflow See other posts from Stack Overflow or by Rnegi
Published on 2010-02-01T05:35:27Z Indexed on 2010/03/30 2:03 UTC
Read the original article Hit count: 1908

Filed under:
|
|

Hi, I've been trying to figure out how to draw a shadow for an UIView that was added inside a UIView with addSubview.

I searched online and read the docs, but the Apple docs simply draw new shapes as shown below. I want to use the Core Graphics to add a shadow to the UIView, but am unsure how to do this to a UIView directly.

CGContextRef myContext = UIGraphicsGetCurrentContext();

//CGContextRef myContext = myCGREF;

CGSize          myShadowOffset = CGSizeMake (10, 10);// 2

CGContextSetShadow (myContext, myShadowOffset, 0);   // 3

CGContextBeginTransparencyLayer (myContext, NULL);// 4

// Your drawing code here// 5

CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);

CGContextFillRect (myContext, CGRectMake (a_view.frame.origin.x, a_view.frame.origin.y , wd, ht));

CGContextEndTransparencyLayer (myContext);// 6

I know I should put this in the SuperView drawRect method, but I don't know how to make it so it adds a shadow to the views I add in addSubView.

Thanks!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview