在QQ音樂上看歌詞時哀卫,經(jīng)常會很疑惑歌詞后面的毛玻璃效果是怎么弄出來的呜呐,經(jīng)過系統(tǒng)的了解 UIToolBar 控件內(nèi)容后,知道毛玻璃效果是怎么實現(xiàn)的了划栓,以下是代碼:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//1.創(chuàng)建UIImageView的對象
UIImageView * bgimageV = [[UIImageView alloc]init];
//2.設(shè)置frame
bgimageV.frame = self.view.bounds;
//3.設(shè)置背景顏色
bgimageV.backgroundColor = [UIColor redColor];
//4.設(shè)置顯示圖片
bgimageV.image = [UIImage imageNamed:@"lol"];
//5.設(shè)置內(nèi)容模式
bgimageV.contentMode = UIViewContentModeScaleAspectFill;
//6.添加毛玻璃
//6.1 創(chuàng)建UIToolBar對象
UIToolbar * toolbar = [[UIToolbar alloc]init];
//6.2 設(shè)置frame
toolbar.frame = bgimageV.bounds;
//6.3 設(shè)置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的樣式變成毛玻璃效果,以下是枚舉的內(nèi)容
typedef NS_ENUM(NSInteger, UIBarStyle) {
UIBarStyleDefault = 0, //默認(rèn)樣式呢撞,也就是白色
UIBarStyleBlack = 1, //樣式的顏色為黑色
//以下2種枚舉已棄用
UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack
UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES
} __TVOS_PROHIBITED;