简体   繁体   中英

objective-c hide round rect buttons

I have three buttons centered on my view called btn_easy, btn_medium, btn_hard. I want to hide all three of these buttons when I click one of them: My .h file has the outlets and method defined as follows:

    IBOutlet UIButton  *btn_easy;
    IBOutlet UIButton  *btn_medium;
    IBOutlet UIButton  *btn_hard;
    @property(nonatomic,retain) IBOutlet UIButton  *btn_easy;
    @property(nonatomic,retain) IBOutlet UIButton  *btn_medium;
    @property(nonatomic,retain) IBOutlet UIButton  *btn_hard;

    -(IBAction)buttonPressed:(id)sender;

After defining these IBOutlets in my .h file I open Interface Builder and make the Connection Outlets from each button from "touch up inside" reference outlet to the "File's Owner". My .m file has the following synthesis:

  @synthesize btn_easy,btn_medium,btn_hard;

And I've tried the following methods in my .m file as well:

-(IBAction)buttonPressed:(id)sender{
  UIButton *button = (UIButton*)sender;
  if([button.titleLabel.text isEqualToString:@"easy"]){
      NSLog(@"easy clicked");
  }
  if([button.titleLabel.text isEqualToString:@"medium"]){
      NSLog(@"medium clicked");
  }
  if([button.titleLabel.text isEqualToString:@"hard"]){
      NSLog(@"hard clicked");
  }
  cover_page.hidden = YES;
  btn_easy.hidden = YES;
  btn_medium.hidden = YES;
  btn_hard.hidden = YES;
  loadingCover.hidden = YES;
 }

but neither of these seem to work for hiding the buttons. I know the method executes correctly however because I have other functions within the method that execute properly, it is just the button hiding that does not work.

You want to make sure that each of your buttons are declared as IBOutlets,

Then make sure inside Interface Builder that your IBAction is connected to each button and your IBOutlets are connected to each corresponding button.

Instead of using hidden try the alpha/opacity being set to 0.

Should be a very simple fix and if this doesn't work then I imagine there is some other code interfacing with those buttons that is stopping from this event happening.

Use this!

 if([[YourButton titleForState:UIControlStateNormal] isEqualToString:@"Text"])
{

}
else {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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