简体   繁体   English

在IB中链接UILabel和UIButton

[英]Link a UILabel and a UIButton in IB

During a time in my app - I make a button a button not enabled 在我的应用程序中的某个时间-我将一个按钮设为未启用按钮

myButton.enabled = NO;

The problem is that I've made my button in IB with an image, and just a UILabel overtop of it. 问题是我已经在IB中创建了带有图像的按钮,并且只有UILabel覆盖了它。 The label does not grey out when the buttons does. 当按钮显示时,标签不会变灰。

In IB - is there a way to link the label to the button? 在IB中-有没有办法将标签链接到按钮?

This is not possible without you doing the linking action yourself, as @Eiko rightly pointed out. 正如@Eiko正确指出的那样,没有您自己执行链接操作,这是不可能的。

It sounds like you need to make your image the background -image of the button, so you can have your label as the button text, like it is intended to be used . 听起来您需要将图片设为按钮的背景图片,因此可以将标签用作按钮文字, 就像打算使用一样 Then you can specify colors, fonts & images for all 4 possible states. 然后,您可以为所有4种可能的状态指定颜色,字体和图像。

If you decide to invent the wheel yourself, by keeping button and label as separate objects, you will have to invent everything around it as well. 如果您决定自己发明轮子,通过将按钮和标签保持为单独的对象,则还必须发明轮子周围的所有东西。

You can add another outlet in your code, ie IBOutlet UILabel *yourLabel; 您可以在代码中添加另一个插座,即IBOutlet UILabel *yourLabel;

Then link this outlet to your label, same procedure as linking the button. 然后将此出口链接到您的标签,方法与链接按钮相同。

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

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