在iOS7通知中心,标签(和分隔线)有一个非常有趣的背景:模糊图像,以及看起来像柔和的光混合模式.
我不确定要搜索什么.关于如何做到这一点的指针将非常感激.
直到现在,我试图通过使用label.textColor = [UIColor colorWithPatternImage:…]将模糊图像的一部分设置为背景来复制效果.这也没有考虑背景全黑(或白色)的情况,并导致文本变得不可读.
但这似乎并不合适.
像这样:
这是我尝试过的:
- (void)viewDidLoad
{
[super viewDidLoad];
const CGFloat fontSize = 25.f;
const Nsstring *text = @"A long-ish string";
CGSize size = [text sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Avenir Next" size:fontSize]}];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80,270,size.width,size.height)];
label.font = [UIFont fontWithName:@"Avenir Next" size:fontSize];
label.textAlignment = NSTextAlignmentNatural;
label.backgroundColor = [UIColor clearColor];
label.text = text;
UIImage *image = [UIImage imageNamed:@"wat@2x"];
UIImage *blurredImage = [image applyBlurWithRadius:20.5 tintColor:[UIColor clearColor] saturationDeltaFactor:1.f maskImage:nil];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[blurredImage applyDarkEffect]];
imageView.frame = self.view.bounds;
CGFloat imgScale = image.scale;
CGRect labelFrame = label.frame;
CGRect realRect = CGRectMake(labelFrame.origin.x * imgScale,labelFrame.origin.y * imgScale,labelFrame.size.width * imgScale,labelFrame.size.height * 2.0);
CGImageRef labelPatternImage = CGImageCreateWithImageInRect(image.CGImage,realRect);
label.textColor = [UIColor colorWithPatternImage:[UIImage imageWithCGImage:labelPatternImage scale:2.f orientation:UIImageOrientationUp]];
CGImageRelease(labelPatternImage);
[self.view addSubview:imageView];
[self.view addSubview:label];
}
此代码导致
Code Result http://caughtinflux.com/static/result.png
如您所见,这与NC标签不同.
编辑
文本的模糊图像背景应尽可能与实际背景对齐.希望我的代码的模拟器截图有助于理解我所说的内容.
解决方法
您是否尝试过调整标签alpha值(听起来很简单)? 您可以试试,也许在将模糊应用到标签之前为模糊添加一点白色.