问题描述
我有collectionView单元格,其中有此文本,我想使图像模糊,如图所示.
I have collectionView Cell In that i have this text,I want to blur the text as shown in image.
我尝试使用UIVisualEffect,但没有得到确切的答复.
I have tried Using UIVisualEffect but i didnt get exact response.
代码: UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
Code: UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
//Blur the UIImage with a CIFilter
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
[gaussianBlurFilter setValue:[NSNumber numberWithFloat: 10] forKey: @"inputRadius"];
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"];
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage];
//Place the UIImage in a UIImageView
UIImageView *newView = [[UIImageView alloc] initWithFrame:self.bounds];
newView.image = endImage;
[self addSubview:newView];
推荐答案
使用 Gaussian Blur 创建UIImage并将图像添加到此textField或Button(无论您拥有什么).
Create an UIImage with Gaussian Blur and add image onto this textField or Button (whatever you have).
这篇关于UICOllectionview单元格的文字模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!