• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding a shadow to a UIImage in a UIImageview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a shadow to a UIImage in a UIImageview


  • Subject: Re: Adding a shadow to a UIImage in a UIImageview
  • From: Development <email@hidden>
  • Date: Sun, 20 Dec 2009 10:06:08 -0700

Ok so after a couple suggestions and rereading the Quartz information on shadows I modified my code but it's mostly all redundant since the shadow color is whatever the image color is and I cant seem to change that. Anyway Below is the code I am trying to use to draw a drop shadow under a UIImage inside of a UIImage view and it just isn't working. Sometimes I get a duplicate of the image with no color change, sometimes the image is clipped randomly and other times the image simply vanishes from the image view: P.S. I realize some of this code is useless but as you can see it was based on the apple example code.

	UIGraphicsBeginImageContext(self.frame.size);
	CGContextRef myContext =  UIGraphicsGetCurrentContext();
    CGSize          myShadowOffset = CGSizeMake (5,  10);// 2
    float           myColorValues[] = {0, 0, 0, .3};// 3
    CGColorRef      myColor;// 4
    CGColorSpaceRef myColorSpace;// 5
	CGImageRef imgRef = rotatingView.image.CGImage;
	CGFloat width = CGImageGetWidth(imgRef);
	CGFloat height = CGImageGetHeight(imgRef);

    CGContextSaveGState(myContext);// 6

    CGContextSetShadow (myContext, myShadowOffset, 5); // 7
    // Your drawing code here// 8
    CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);
   // CGContextDrawImage(myContext, CGRectMake(0, 0, width, height), imgRef);
	[rotatingView.image drawInRect:self.frame];
    myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9
    myColor = CGColorCreate (myColorSpace, myColorValues);// 10
    CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);// 11
    // Your drawing code here// 12
    CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
    //CGContextDrawImage(myContext, CGRectMake (width/3-75,height/2-100,width/4,height/4),imgRef);
	[rotatingView.image drawInRect:CGRectMake (width/3-75,height/2-100,width/4,height/4)];
    CGColorRelease (myColor);// 13
    CGColorSpaceRelease (myColorSpace); // 14

	UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
	CGContextRestoreGState(myContext);
	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

References: 
 >Adding a shadow to a UIImage in a UIImageview (From: Development <email@hidden>)

  • Prev by Date: Charisse Marie Napenas/Cebu/Lexmark is out of the office.
  • Next by Date: Re: Core Data - Importing using NSOperation - Problems on main thread
  • Previous by thread: Adding a shadow to a UIImage in a UIImageview
  • Next by thread: NSTableview datasource issues
  • Index(es):
    • Date
    • Thread