简体   繁体   English

如何获取UIButton中的点击计数?

[英]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. 我的设置页面上有两个UIButton ,一个按钮用于增加文本的字体大小,另一个按钮用于减小文本的字体大小。 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. 但是我需要做的就是,当用户点击UIButton来增加字体大小时,它需要切开18pt,然后用户再次在同一按钮中再次点击或一次,它需要将字体大小设置为24pt,然后再次点击相同的按钮会导致字体大小固定为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. 您必须在类中某处管理按钮的状态,例如在头文件int counterOfFontIncrease头文件中声明一个变量,然后每次按钮单击并置于类似条件时就增加此变量。

if (counterOfFontIncrease == 3)
      {

         counterOfFontIncrease = 1;
      }

Do this for decreasing te font button as well. 这样做也是为了减少字体按钮。

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

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