如何以编程方式更改名称以区分Xcode可视调试器中的UIView? [英] How do I change names programmatically to tell apart UIViews in Xcode visual debugger?

查看:49
本文介绍了如何以编程方式更改名称以区分Xcode可视调试器中的UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Xcode可视调试器中重命名视图?UIViews繁多,因此几乎不可能分辨出哪个uiview是一个约束.

How do I rename views in Xcode visual debugger? It's a sea of UIViews so it's nearly impossible to tell which uiview a constraint is for.

UIViewControllers在显示UIViews时显示标题,除非它是派生类它是UIView.您如何区分他们?

UIViewControllers show titles while for UIViews unless it's a derived class it's UIView. How do you tell them apart?

抓住重点

这似乎是推荐答案

按住Control键并单击所需的视图,然后在上下文菜单中选择打印描述":

Control-click the view in question and choose Print Description in the contextual menu:

<UIView: 0x7fbec8508420; frame = (30 34; 163 117); autoresize = RM+BM; 
    layer = <CALayer: 0x6000019c65c0>>

通常足以识别视图.如果不是,您可以向视图提出问题,尽管语法有些棘手:

Often that will be enough to identify the view. If it isn't, you can ask the view questions, though the syntax is a little tricky:

(lldb) expr -l objc -O -- [(UIView*)0x7fbec8508420 backgroundColor]
<UIDynamicModifiedColor: 0x6000017c6f10; contrast = normal, 
    baseColor = <UIDynamicSystemColor: 0x6000019c6600; name = systemYellowColor>>


我有时使用的另一个技巧是为视图提供标识符.一个鲜为人知的技巧是,图层具有您可以随意使用的 name .一个视图有一层.所以我声明一个扩展名:


Another trick I sometimes use is to give the view an identifier. A little-known trick is that a layer has a name that you can use as you like. And a view has a layer. So I declare an extension:

extension UIView {
    @objc var name : String? { return layer.name }
}

现在,您可以向视图询问其名称.您可以在代码中或在情节提要中(使用运行时属性)分配名称.

Now you can ask the view for its name. You can assign the name in code or (using runtime attributes) in the storyboard.

这篇关于如何以编程方式更改名称以区分Xcode可视调试器中的UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆