我想在UIImage
/UIImageView
/UIView
上添加一个淡化的阴影/外发光,但是我完全不懂Core Graphics
。
编辑: 请帮忙!!
我想在UIImage
/UIImageView
/UIView
上添加一个淡化的阴影/外发光,但是我完全不懂Core Graphics
。
编辑: 请帮忙!!
采用Cirrostratus所概述的方法,保留其缓存副本,并应用变换来在拖动时改变图像的大小和/或位置。
(警告:这不是功能/测试代码,但可以让您开始)
-(UIImage*)addGlowToImage:(UIImage*)imageInput;
{
CGRect newSize = imageInput.bounds;
CGImageRef theImage = imageInput.CGImage;
// expand the size to handle the "glow"
newSize.size.width += 6.0;
newSize.size.height += 6.0;
UIGraphicsBeginImageContext(newSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginTransparencyLayerWithRect(ctx, newSize, NULL);
CGContextClearRect(ctx, newSize);
// you can repeat this process to build glow.
CGContextDrawImage(ctx, newSize, theImage);
CGContextSetAlpha(ctx, 0.2);
CGContextEndTransparencyLayer(ctx);
// draw the original image into the context, offset to be centered;
CGRect centerRect = inputImage.bounds;
centerRect.origin.x += 3.0;
centerRect.origin.y += 3.0;
CGContextDrawImage(ctx, centerRect, theImage);
result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
// assumes UIImage *cachedImage = [self addGlowToImage:origImage]; has been called already.
// assumes ivars for scale exists
CGRect newRect = cachedImage.bounds;
newRect.size.width += scale;
newRect.size.height += scale;
[cachedImage drawInRect:newRect]; // image will be scaled to fill destination rectangle.
一定要看看苹果的文档。一个好的起点是Quartz 2D编程指南。
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(100, 66, 112, 112)];
shadowView.layer.shadowColor = [[UIColor blackColor] CGColor];
shadowView.layer.shadowOpacity = .4;
shadowView.layer.shadowOffset = CGSizeZero;
shadowView.layer.masksToBounds = NO;
如果你可以使用收音机,就添加这个:
shadowView.layer.shadowRadius = 10.0f;