Swift iOS : 模糊化

RecoReco發表於2017-05-25

iOS的模糊化,會讓介面很炫酷,用了不能停。本案例使用了FXBlurView,對圖片進行模糊處理。

使用Pod檔案:

target 'five' do
  use_frameworks!
  pod 'FXBlurView', '~> 1.6.4'
end複製程式碼

然後執行pod install:

pod install --verbose --no-repo-update複製程式碼

如下程式碼可以直接編譯執行:

import UIKit
import FXBlurView
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow();
        self.window?.frame=UIScreen.main.bounds;
        self.window?.makeKeyAndVisible();
        self.window?.rootViewController = Page()
        return true
    }
}
class Page: UIViewController {
    var backgroundImageView:UIImageView?
    var frostedView = FXBlurView()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.backgroundImageView = UIImageView()
        self.backgroundImageView!.frame = self.view.frame
        self.backgroundImageView!.contentMode = .scaleToFill
        view.addSubview(self.backgroundImageView!)
        frostedView.underlyingView = self.backgroundImageView!
        frostedView.isDynamic = true
        frostedView.tintColor = UIColor.black
        frostedView.frame = self.view.frame
        self.view.addSubview(frostedView)
        self.backgroundImageView?.image = UIImage(named: "1.jpg")
        self.frostedView.updateAsynchronously(true, completion: nil)
    }
}複製程式碼

這是我使用的圖(檔名為1.jpg)記得拖放到你的工程內:

Swift iOS : 模糊化

相關文章