简体   繁体   English

XCode 6 / Swift按钮标签

[英]XCode 6/Swift button label

The code below shows what I have found by searching for help but have been unable to find something that shows me what I am really looking for. 下面的代码显示了我通过寻求帮助找到的内容,但是找不到我真正想要的内容。 I'm trying to get the value of the button's label that shows in the Identity Inspector under the Document section and on the scene tree. 我试图获取在“文档”部分和“场景树”下的“身份检查器”中显示的按钮标签的值。

在此输入图像描述

@IBAction func pressedKeypad(sender: UIButton) {
    print(sender.titleLabel?.text)
    print(sender.titleLabel)
    print(" keytitle is \(keytitle).")        
}

The above code yields these three outputs, but they are not what I want. 上面的代码产生了这三个输出,但是它们不是我想要的。

Optional("3")

Optional(<UIButtonLabel: 0x7b7b10a0; frame = (27 14; 18.5 36); text = '3'; alpha = 0.2; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7b7b11c0>>)

keytitle is 3

The label shown under the Document section ( btn02 in your screen shot) is purely internal to Interface Builder and cannot be retrieved via code. “文档”部分(屏幕截图中的btn02 )下显示的标签纯粹是Interface Builder的内部标签,无法通过代码检索。 When the app runs and the nib loads, the label doesn't even exist . 当应用运行且笔尖加载时,标签甚至不存在 It is purely for your use in identifying a view within Interface Builder. 它纯粹是用于在Interface Builder中识别视图。

If the problem is that you are looking for a way to identify which button sent you the pressedKeypad message, you can use something like its tag (which you can also assign in Interface Builder: you assign it as a string but it arrives to you as a number). 如果问题在于您正在寻找一种方法来识别哪个按钮向您发送了pressedKeypad消息,您可以使用类似其tag (您也可以在Interface Builder中分配:您将其指定为字符串但它会以一个号码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM