微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iOS 7通知中心与标签一样

在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值(听起来很简单)? 您可以试试,也许在将模糊应用到标签之前为模糊添加一点白色.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐