简体   繁体   中英

UILabel blur only text

I'm trying to blur the text of a label that I create programmatically, I've been able to apply the blur, but only to the label itself, leaving the text readable and blurying only the background behind the label.

Is there any way to blur only the text?

Thanks in advance.

EDIT:

Heres my code till now:

UILabel *lblVericalName = 
    [[UILabel alloc]initWithFrame:CGRectMake(-95, 
                                             _viewVerticalStick.frame.size.height-120,
                                             200,
                                             20)];
lblVericalName.tag = [tarefaDiaArray.idTarefaDia integerValue];
lblVericalName.text = tarefaDiaArray.nomeTarefa;

lblVericalName.transform=CGAffineTransformMakeRotation( M_PI+89.55 );

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *blurEffectView = 
    [[UIVisualEffectView alloc] initWithEffect:blurEffect];

blurEffectView.frame = lblVericalName.bounds;

blurEffectView.autoresizingMask = 
    UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;


[viewStickBackground addSubview:lblVericalName];

if ([tarefaDiaArray.tarefaPremium intValue] ==1) {
    //[viewStickBackground addSubview:blurEffectView];
    [lblVericalName addSubview:blurEffectView];
}

EDIT 2:

文字模糊

UPDATE

I've made some progress, now I have this:

我的形象

and I need to make it look like this:

我想要的是

here is the code that i'm using:

lblNomeVertical.textColor = [UIColor colorWithRed:0.494 green:0.494 blue:0.494 alpha:0.8];

lblNomeVertical.layer.shadowOffset = CGSizeMake(1, 1.1); 
lblNomeVertical.layer.shadowColor = [UIColor colorWithRed:0.827 green:0.827 blue:0.827 alpha:1].CGColor; 
lblNomeVertical.layer.shadowRadius = 1.0;
lblNomeVertical.layer.shadowOpacity = 1;

Instead of using a label, use a drawing. In code, draw the text yourself and blur it yourself (eg with a box blur or a gaussian blur CIFilter). Now just place that drawing in front of your background. In that way, I was able to achieve this, which seems to be the sort of thing you are after (of course it can be more blurry if you want):

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM