LoginSignup
26
23

More than 5 years have passed since last update.

コピペでできるSwiftでスクリーンショットを撮る

Last updated at Posted at 2017-06-26

画面のスクリーンショットを撮る。

//コンテキスト開始
UIGraphicsBeginImageContextWithOptions(UIScreen.main.bounds.size, false, 0.0)
//viewを書き出す
self.view.drawHierarchy(in: self.view.bounds, afterScreenUpdates: true)
// imageにコンテキストの内容を書き出す
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
//コンテキストを閉じる
UIGraphicsEndImageContext()
// imageをカメラロールに保存
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

これでスクショが取れます

26
23
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
23