文本模糊与UICOllectionview单元格

时间:2016-06-21 10:31:50

标签: ios uicollectionviewcell blur uivisualeffectview uiblureffect

我有collectionView Cell我有这个文字,我想模糊文字,如图所示。

我尝试过使用UIVisualEffect,但我没有得到确切的回复。

代码:         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];

1 个答案:

答案 0 :(得分:0)

使用高斯模糊创建一个UIImage,并将图像添加到此textField或Button(无论你有什么)。