`

iOS today插件毛玻璃效果

阅读更多
这里说的毛玻璃不是背景,而是文字以及按钮的毛玻璃效果.比如下图里副标题文字的颜色,他们的是有毛玻璃效果的,颜色会跟着背景而变.

最近被好几个人问到today插件的毛玻璃效果是怎么做的.
先上一张图,顺便为sina打打广告


在today插件里,想要毛玻璃,那些在本地app里使用的方法在today里都不管用了 (第三方的库和系统提供的毛玻璃方法以及toolbar).
这里需要用的是UIVisualEffectView.

代码:
UIVibrancyEffect * effect = [UIVibrancyEffect notificationCenterVibrancyEffect];
    UIVisualEffectView * blurBackgroundView = [[UIVisualEffectView alloc] initWithEffect:effect];
    blurBackgroundView.frame = CGRectMake(0, 0, self.tableWidth, [self heightInDataSourceAtIndexPath:indexPath]);
    [cell addSubview:blurBackgroundView];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 30, 50, 0.5)];
    line.backgroundColor = [UIColor whiteColor];
    [blurBackgroundView.contentView addSubview:line];



UIVibrancyEffect * effect = [UIVibrancyEffect notificationCenterVibrancyEffect];声明了要使用系统通知中心的效果.然后用这个效果创建一个UIVisualEffectView,这时,不管在这个UIVisualEffectView上加什么组件,只要是白色的,就都会自动变成毛玻璃(imageView不行).
上边代码是画了一条毛玻璃的线.

大家看我发出来的截图,有的文字是毛玻璃效果,有的不是,如果一个组件不想要毛玻璃,那就直接加在cell上就行了,如果想要毛玻璃效果,才加在UIVisualEffectView上.
  • 大小: 1.4 MB
  • 大小: 241.1 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics