简体   繁体   中英

How to get the tap count in UIButton?

I am having two UIButton in my setting page, one button is to increase the font size of the text and other is to decrease the font size of the text. But all I have to need is when the user tap the UIButton for increasing font size, it need to incise 18pt, then the user again tap or one more time in the same button it need to set the font size to 24pt, then again taping the same button result in in cement of font size to 32pt. I need to limit or there tap counts. Vise versa the same effect in decreasing font size button.

-(IBAction)_clickfontsizeincrease:(id)sender
{ 
      self.multiPageView.font = [UIFont systemFontOfSize:30.0f];   
}

-(IBAction)_clickfontsizedecrease:(id)sender
{
        self.multiPageView.font = [UIFont systemFontOfSize:10.0f];
}

How to do this? Thanks in advance.

static int tapCount = 0;
- (IBAction) buttonTapped :(id)sender {
    tapCount++;

    // Based upon tapCount condition you can do whatever you want.

}
float current_font_size;

-(id) init
{
    current_font_size = 10f;
}

-(IBAction)_clickfontsizeincrease:(id)sender
{
      current_font_size += 8;
      self.multiPageView.font = [UIFont systemFontOfSize:current_font_size];

}
-(IBAction)_clickfontsizedecrease:(id)sender
{
        current_font_size -= 8;
        self.multiPageView.font = [UIFont systemFontOfSize:current_font_size];
}

You have to manage the state of the button somewhere in the class, for example declare a variable in header file int counterOfFontIncrease , then increases this variable each time the button click and put at condition like.

if (counterOfFontIncrease == 3)
      {

         counterOfFontIncrease = 1;
      }

Do this for decreasing te font button as well.

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