cau*_*lux 7 objective-c ios quartz-core
在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];
}
Run Code Online (Sandbox Code Playgroud)
此代码导致
代码结果http://caughtinflux.com/static/result.png
如您所见,这与NC标签不相似.
编辑
文本的模糊图像背景应尽可能与实际背景对齐.希望我的代码的模拟器截图有助于理解我所说的内容.
| 归档时间: |
|
| 查看次数: |
1304 次 |
| 最近记录: |