0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS UIViewの階層構造をprintする extension by Swift 3.0

Posted at

隠れているUIViewを確認するための便利関数を自作

Utility.swift
import Funcation
import UIKit

extension UIWindow {
    func printSubviewHierarchy() {
        var tabs:String = ""
        printSubviews(subviews: self.subviews, tabs: &tabs)
    }
    
    private func printSubviews(subviews: [UIView], tabs:inout String) {
        tabs += " "
        for view in subviews {
            print(tabs + "\(view.self)")
            printSubviews(subviews: view.subviews, tabs: &tabs)
        }
        tabs.remove(at: tabs.index(before: tabs.endIndex))
    }
}

使用例

ViewController.swift
    @IBAction func tapped(_ sender: UIButton){
        self.view.window?.printSubviewHierarchy()
    }

結果表示例


DebugWindow
 <UILayoutContainerView: ...
  <UINavigationTransitionVIew: ...
    :

0
1
2

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?