UIImage and shadows, WAS: Re: Please if some one knows
UIImage and shadows, WAS: Re: Please if some one knows
- Subject: UIImage and shadows, WAS: Re: Please if some one knows
- From: Development <email@hidden>
- Date: Mon, 21 Dec 2009 18:29:59 -0700
Ok ok, sorry for double posting. Honestly I'm thinking I'm trying to do something that simply isn't possible though.
I'll try my question again. Ok, I have a UIImageView. I am trying to draw a shadow under the UIImage it holds. Now if I make the UIImageView's bounds some ungodly size, like the size of the screen it draws shadows perfectly but obviously this is not acceptable. So I don't understand what I am doing wrong. I've tried turning off the clipstobounds but that doesn't help unless the context I am drawing is is clipping in which case I do not know how to turn it off. But at least in the UIImageView it is not clipping.
So the first question: How do I turn of clipping in the context I'm drawing too?
Second, is the problem something else in my code? Like I said before I get a perfect shadow unfortunately it is clipped to the edges of the view so it's useless.
I have tried to enlarge the view by the amount of the offset but this does nothing except make the view bigger. The image still draws in the same upper right location rather than the center as I thought I had set it to with the content mode. I've also tried using the CG draw image method but it draws upside down and since I don't want to go through flipping the image every time I add a shadow I gave up on that. It didn't give me any better results though otherwise I'd have used it. Do I need to do some kind of Affinetransform to translate the context?
Lastly if I am wasting my time with this please let me know. I've spent hours now on Google and cannot find any examples of adding a shadow to a UIImage, at least not this way.
-(void)addShadow:(CGSize)myShadowOffset darkness:(CGFloat)darkness spread:(CGFloat)spread
{
UIGraphicsBeginImageContext(rotatingView.bounds.size);
CGContextRef myContext = UIGraphicsGetCurrentContext();
float myColorValues[] = {0, 0, 0, darkness};
CGColorRef myColor;
CGColorSpaceRef myColorSpace;
myColorSpace = CGColorSpaceCreateDeviceRGB ();
myColor = CGColorCreate (myColorSpace, myColorValues);
CGContextSetShadowWithColor (myContext, myShadowOffset, spread, myColor);
[rotatingView.image drawInRect:rotatingView.bounds
blendMode:kCGBlendModeNormal alpha:1.0];
CGColorRelease (myColor);
CGColorSpaceRelease (myColorSpace);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
rotatingView.image = imageCopy;
}_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden