我有一个UIImageView,我想在后面添加一个阴影.我希望苹果将其作为一种财产,但他们必须为我们的程序员做很多事情,所以我需要问这个问题.
我发现
和
但选定的答案对我不起作用.
我有一个UIImage,其中可能有一些透明像素,我需要创建一个新的UIImage,其中非透明像素变暗,有什么办法可以做到这一点吗?我正在考虑使用UIBezierPath,但我不知道如何只为非透明像素做这件事.
我正在尝试为图像添加一个小阴影,就像App Store中的图标阴影一样.现在我正在使用以下代码来围绕我的图像的角落.有谁知道我怎么能适应它来添加一个小阴影?
- (UIImage *)roundCornersOfImage:(UIImage *)source height:(int)height width:(int)width {
int w = width;
int h = height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextBeginPath(imageContext);
CGRect rect = CGRectMake(0, 0, w, h);
addRoundedRectToPath(imageContext, rect, 10, 10);
CGContextClosePath(imageContext);
CGContextClip(imageContext);
CGContextDrawImage(imageContext, CGRectMake(0, 0, w, h), source.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(imageContext);
CGContextRelease(imageContext);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
Run Code Online (Sandbox Code Playgroud)
"addRoundedRectToPath"指的是另一种明显围绕角落的方法.
需要专家的帮助
我正在制作 UIButton 自定义,我正在裁剪背景并在 UIButton 上显示如下。
[self setBackgroundImage:[self getSingleColorImageForLinear:self.frame] forState:UIControlStateSelected];
//Method to make take image
-(UIImage *)getSingleColorImageForLinear:(CGRect)frame{
CGSize size = CGSizeMake(frame.size.width,frame.size.height);
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
size_t gradientNumberOfLocations = 1;
CGFloat gradientLocations[1] = { 0.0 };
CGFloat gradientComponents[4] = { 0, 0, 0, 0.3, };
CGGradientRef gradient = CGGradientCreateWithColorComponents (colorspace, gradientComponents, gradientLocations, gradientNumberOfLocations);
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGGradientRelease(gradient);
CGColorSpaceRelease(colorspace);
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
现在我想应用,在 Adobe Photoshop 中看到的投影属性到这个图像, …