2 yue1liang1chuan yue1liang1chuan 于 2013.01.16 10:18 提问

设置按钮在十分钟之内禁用

ios应用中的button:

_Button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *shareIMG = [UIImage imageNamed:@"button.png"];
[_Button setBackgroundImage:shareIMG forState:UIControlStateNormal];
[_Button setBackgroundImage:[UIImage imageNamed:@"button_active.png"] forState:UIControlStateHighlighted];
[_Button addSubview:titleLabel];

UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 3, shareIMG.size.width, shareIMG.size.height)];
[titleLabel setTextAlignment:UITextAlignmentCenter];
[titleLabel setText:@"Button";
[_Button addSubview:titleLabel];
[titleLabel release];
[_Button setFrame:CGRectMake(2 * self.sendPushButton.frame.origin.x + self.sendPushButton.frame.size.width , 380 - liteIndent1 - liteIndent2 + iphone5Fix, shareIMG.size.width, shareIMG.size.height)];
[self addSubview:_Button];

怎么样设置这个按钮暂停button_non_active.png,并且在点击后10分钟之内不能再次点击?

3个回答

garaster
garaster   2013.01.16 10:55
已采纳
// disable button
[_Button setEnabled:NO];

// run a selector after 10 minutes
[_Button performSelector:@selector(onEnableButton:) withObject:_Button afterDelay:(10.0 * 60.0)]


- (void) onEnableButton:(UIButton *)sender
{
 [sender setEnabled:YES];
}
Kill_it
Kill_it   2013.01.16 11:05
  _Button = [UIButton buttonWithType:UIButtonTypeCustom];
    [_Button setImage:[UIImage imageNamed:@"button_active.png"] forState:UIControlStateNormal];
    [_Button setImage:[UIImage imageNamed:@"button_non_active.png"] forState:UIControlStateDisabled];
    [_Button addSubview:titleLabel];
   [_Button setEnabled:NO];

    int64_t delayInSeconds = 60.0 * 10;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
       [_Button setEnabled:YES];
    });
for_2012
for_2012   2013.01.16 15:06

使用 `

 btn.enabled=NO;`

  NSTimer  *   notificationTimer = [NSTimer scheduledTimerWithTimeInterval:10*60.0 target:self selector:@selector(enable) userInfo:nil repeats:No];

    -(void)enable
    {
    btn.enabled=YES;
    }

根据需要修改yes或者no

Csdn user default icon
上传中...
上传图片
插入图片