在iOS7的通知中心中,标签(以及分隔线)具有非常有趣的背景:模糊图像和类似柔光混合模式的效果。
我不确定应该搜索什么。非常感谢能够给出如何实现这个效果的指针。
到目前为止,我尝试通过使用
但这似乎不是完全正确的。
像这样:
这是我尝试过的方法:
这段代码的结果如下: Code Result http://caughtinflux.com/static/result.png
从图中可以看出,它与NC标签不相似。 编辑
文本的模糊图像背景应尽可能与实际背景对齐。希望我代码的模拟器截图有助于理解我的意思。
到目前为止,我尝试通过使用
label.textColor = [UIColor colorWithPatternImage:...]
将模糊图像的一部分设置为背景来复制效果。但这也无法解决背景全是黑色(或白色)的情况,并导致文本变得不可读。但这似乎不是完全正确的。
像这样:
![Blur example](https://istack.dev59.com/ekq8i.webp)
- (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标签不相似。 编辑
文本的模糊图像背景应尽可能与实际背景对齐。希望我代码的模拟器截图有助于理解我的意思。