在iOS7通知中心,标签(和分隔线)有一个非常有趣的背景:模糊图像和看起来像柔光混合模式。iOS 7通知中心喜欢标签
我不确定搜索什么。关于如何做到这一点的指针将非常感激。
到现在为止,我试图通过使用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:@"[email protected]"];
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标签。
编辑
文本应与实际背景,尽可能一致的模糊图像背景。希望我的代码的模拟器截图有助于理解我在说什么。
你的第二个评论是现货!模糊之前,我在图像上添加了轻微的白色色调,与我试图复制的图像非常接近。将blur设置为标签的textColor很好用,就像我上面的代码一样。谢谢!当我的代码使用图片时,Greg的回答也显示了如何在iOS中使用新的快照API来创建相同的图片。 – caughtinflux
如何滚动? @caughtinflux –
你必须不断调整图像的contentOffset的滚动视图 – caughtinflux