---
title: "iOS today插件毛玻璃效果"
author: "82934162"
date: "2015-01-30T17:31:20Z"
tags: []
categories: ["移动开发"]
slug: "ios-today"
draft: false
lastmod: "2015-02-12T14:18:39Z"
id: 2181881
url: "https://borissun.iteye.com/blog/2181881"
---

这里说的毛玻璃不是背景,而是文字以及按钮的毛玻璃效果.比如下图里副标题文字的颜色,他们的是有毛玻璃效果的,颜色会跟着背景而变.

最近被好几个人问到today插件的毛玻璃效果是怎么做的.
先上一张图,顺便为sina打打广告
![](http://dl2.iteye.com/upload/attachment/0106/0347/115a3be9-0980-35bc-bd98-bf85da04b2da.png)

在today插件里,想要毛玻璃,那些在本地app里使用的方法在today里都不管用了 (第三方的库和系统提供的毛玻璃方法以及toolbar).
这里需要用的是UIVisualEffectView.

代码:

```c

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 = ;声明了要使用系统通知中心的效果.然后用这个效果创建一个UIVisualEffectView,这时,不管在这个UIVisualEffectView上加什么组件,只要是白色的,就都会自动变成毛玻璃(imageView不行).
上边代码是画了一条毛玻璃的线.

大家看我发出来的截图,有的文字是毛玻璃效果,有的不是,如果一个组件不想要毛玻璃,那就直接加在cell上就行了,如果想要毛玻璃效果,才加在UIVisualEffectView上.