让视图的背景图实现毛玻璃的虚幻效果,可以通过 UIBlurEffect 来呈现,具体操作以 TableView 的 Cell 为例,具体 code 实现如下;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"imgPlaceholder"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; // 设置资源图片
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; // 磨砂效果,枚举中还提供另外几种效果,可供尝试
UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
effectview.frame = CGRectMake(0, 0, SCREEN_WIDTH, 150); // 设置虚化背景尺寸,整个视图可以直接 bounds
[cell.backgroundView addSubview:effectview];
注:此处最好将图层上的子视图模板的背景色都置为 clearColor 以免影响美观效果
![](https://img.haomeiwen.com/i3095156/462e2b896eff68c7.png)
以上便是此次分享的全部内容,希望能对大家有所帮助!
网友评论