UI05_ 製造一個毛玻璃效果

首先,先創建一個UIImageView的對象.
注意, 本文已將ARC改爲MRC.

UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"222.jpg"]];
    imageview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:imageview];
    [imageview release];

第二步, 我們需要創建出一個毛玻璃效果.

    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

第三步,創建一個毛玻璃視圖,指定效果 — iOS8.0之後出現的效果.

UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];

第四步,設定視圖的大小, 與viewControll的view同大, 因爲imageView就是屏幕大.

effectView.frame = imageview.frame;

最後一步, 將效果視圖加至imageView上.

 [imageview addSubview:effectView];

毛玻璃效果有三種.
UIBlurEffectStyleExtraLight,
UIBlurEffectStyleLight,
UIBlurEffectStyleDark

沒有添加毛玻璃效果時:
ExtraLight
Light
Dark

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章