开发者

objective-c hide round rect buttons

开发者 https://www.devze.com 2023-01-25 21:46 出处:网络
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 fol

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开发者_如何学Python)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 {

}

0

精彩评论

暂无评论...
验证码 换一张
取 消