3
我想添加陰影到UIImage視圖。我得到一個陰影,但它被剪切到圖像視圖的邊緣,我不知道爲什麼,因爲我正確地將uiimageview.clipsToBounds設置爲NO。下面是代碼:我想添加陰影到UImageView
-(void)addShadow
{
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef myContext = UIGraphicsGetCurrentContext();
float myColorValues[] = {0, 0, 0, darkness};// 3
CGColorRef myColor;// 4
CGColorSpaceRef myColorSpace;
CGContextSaveGState(myContext);// 6
myColorSpace = CGColorSpaceCreateDeviceRGB();// 9
myColor = CGColorCreate (myColorSpace, myColorValues);// 10
CGContextSetShadowWithColor (myContext, myShadowOffset, spread, myColor);// 11
// Your drawing code here// 12
// CGContextDrawImage(myContext, rotatingView.frame,imgRef);
rotatingView.clipsToBounds = NO;
[rotatingView.image drawInRect:rotatingView.frame
blendMode:kCGBlendModeNormal alpha:.5];
CGColorRelease (myColor);// 13
CGColorSpaceRelease (myColorSpace); // 14
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(myContext);
UIGraphicsEndImageContext();
rotatingView.image = imageCopy;
}
我試着添加這段代碼,但我仍然以修剪過的陰影結束。 – April 2009-12-21 23:40:29
我是否在添加上面的代碼時做了其他錯誤?或者該圖層是否是影子? – April 2009-12-22 01:14:43
該圖層應該是陰影。你確實將clipsToBounds設置爲NO? – 2009-12-22 01:26:23