Get the frame of UIBarButtonItem in Swift?

后端 未结 3 1763
长情又很酷
长情又很酷 2020-12-06 09:44

how could I get the frame of a rightbarbuttonItem in swift? I found this : UIBarButtonItem: How can I find its frame? but it says cannot convert NSString to UIView, or canno

3条回答
  •  死守一世寂寞
    2020-12-06 10:27

    In Swift4, XCode9

        for view in (self.navigationController?.navigationBar.subviews)! {
            if let findClass = NSClassFromString("_UINavigationBarContentView") {
                if view.isKind(of: findClass) {
                    if let barView = self.navigationItem.rightBarButtonItem?.value(forKey: "view") as? UIView {
                        let barFrame = barView.frame
                        let rect = barView.convert(barFrame, to: view)
                    }
                }
            }
        }
    

提交回复
热议问题