在QQ音乐上看歌词时,经常会很疑惑歌词后面的毛玻璃效果是怎么弄出来的,经过系统的了解 UIToolBar 控件内容后,知道毛玻璃效果是怎么实现的了,以下是代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.创建UIImageView的对象
UIImageView * bgimageV = [[UIImageView alloc]init];
//2.设置frame
bgimageV.frame = self.view.bounds;
//3.设置背景颜色
bgimageV.backgroundColor = [UIColor redColor];
//4.设置显示图片
bgimageV.image = [UIImage imageNamed:@"lol"];
//5.设置内容模式
bgimageV.contentMode = UIViewContentModeScaleAspectFill;
//6.添加毛玻璃
//6.1 创建UIToolBar对象
UIToolbar * toolbar = [[UIToolbar alloc]init];
//6.2 设置frame
toolbar.frame = bgimageV.bounds;
//6.3 设置toolbar的样式
toolbar.barStyle = UIBarStyleBlack;
//6.4 将UIToolBar添加到bgimageV中
[bgimageV addSubview:toolbar];
//将对象添加到控制器的View中
[self.view addSubview:bgimageV];
}
其中
bgimageV.bounds 等同于 CGRectMake(0, 0, bgimageV.frame.size.width, bgimageV.frame.size.height);
主要就是通过UIToolBar的样式变成毛玻璃效果,以下是枚举的内容
typedef NS_ENUM(NSInteger, UIBarStyle) {
UIBarStyleDefault = 0, //默认样式,也就是白色
UIBarStyleBlack = 1, //样式的颜色为黑色
//以下2种枚举已弃用
UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack
UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES
} __TVOS_PROHIBITED;