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分钟之内不能再次点击?
// 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];
}
_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];
});
使用 `
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