简体   繁体   English

将按钮禁用为灰色-Objective C

[英]Disabling a Button to gray color-Objective C

Hi, I am new to objective C.I have created two buttons using interface builder.Instead of writing two UIButton actions I have pointed both of the buttons to -(IBAction)buttonPressed:(id)sender;If i press one Button then the other button should be disabled(showing gray and should not allow to click).How to set this.[button1 setEnabled:NO] will do.But how to check which button has been pressed.Is it like (button.isSelected:YES).And How to set that to gray color.嗨,我是目标 C 的新手。我使用界面生成器创建了两个按钮。我没有编写两个 UIButton 动作,而是将两个按钮都指向 -(IBAction)buttonPressed:(id)sender;如果我按下一个按钮,那么其他按钮应该被禁用(显示灰色并且不允许点击)。如何设置这个。[button1 setEnabled:NO]会做。但是如何检查哪个按钮被按下了。它像(button.isSelected:YES) .以及如何将其设置为灰色。

- (IBAction)buttonPressed:(id)sender
{
        if ([myButton.isSelected:YES]) //Invalid receiver type BOOL
          {                            //No '-' method found //cast to pointer to  integer of different size warnings.
                [myEventLog setEnabled:NO];
                myTextView.text = @"Processing the request!!";
        }
}

Processing the request doesnt get printed on the UITextView.处理请求不会打印在 UITextView 上。

The sender argument is the button that is sending the action. sender参数是发送操作的按钮。

 if (sender == myButton) {
       [myEventLog setEnabled:NO];
 } else if (sender == myEventLog) {
       [myButton setEnabled:NO];
 }

That's assuming that myButton and myEventLog are your buttons.假设 myButton 和 myEventLog 是您的按钮。

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

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