【问题标题】:How to get the tap count in UIButton?如何获取 UIButton 中的点击次数?
【发布时间】:2012-05-11 06:40:31
【问题描述】:

我的设置页面中有两个UIButton,一个按钮是增加文本的字体大小,另一个是减小文本的字体大小。但我所需要的只是当用户点击UIButton 以增加字体大小时,它需要切割18pt,然后用户再次点击或在同一个按钮上再点击一次它需要将字体大小设置为24pt,然后再次点击相同的按钮导致字体大小为 32pt。我需要限制或有水龙头计数。反之亦然,减小字体大小按钮的效果相同。

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

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

如何做到这一点?提前致谢。

【问题讨论】:

    标签: iphone ios uibutton uitouch


    【解决方案1】:
    static int tapCount = 0;
    - (IBAction) buttonTapped :(id)sender {
        tapCount++;
    
        // Based upon tapCount condition you can do whatever you want.
    
    }
    

    【讨论】:

    • @stackiphone - 从什么意义上解释?
    【解决方案2】:
    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];
    }
    

    【讨论】:

    • 但是如何获得点击次数....这是我的想法,但是需要通过点击按钮来获得增加
    • 使用另一个 int 并计算点击次数
    【解决方案3】:

    你必须在类中的某处管理按钮的状态,例如在头文件int counterOfFontIncrease中声明一个变量,然后在每次按钮单击时增加这个变量并放置在类似的条件下。

    if (counterOfFontIncrease == 3)
          {
    
             counterOfFontIncrease = 1;
          }
    

    这样做也是为了减小字体按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多