我是 iOS 开发的新手。我想显示UIButton
文本 1 秒,再显示 1 秒不显示文本。谁能告诉我iOS中的逻辑?
问问题
68 次
6 回答
1
将此方法添加到您的 .m 文件中
- (void) changeNameOfTheButton{
[self performSelector:@selector(changeNameOfTheButton) withObject:nil afterDelay:1.0];
if ([button.titleLabel.text isEqualToString:@""]){
[button setTitle:@"Title 1" forState:UIControlStateNormal];
}
else{
[button setTitle:@"" forState:UIControlStateNormal];
}
}
然后在您的viewDidLoad中调用上述方法,如下所示:
[self changeNameOfTheButton];
于 2013-02-26T13:12:36.530 回答
1
使用 1.0NSTimer
的常规TimeInterval
,更改文本UIButton
于 2013-02-26T13:07:30.023 回答
0
try like this...
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(animateButton) userInfo:nil repeats:YES];
-(void)animateButton
{
if([button.titleLabel.text isEqualToString:@""])
[button setTitle:@"your text" forState:UIControlStateNormal];
else
[button setTitle:@"" forState:UIControlStateNormal];
}
于 2013-02-26T13:18:13.637 回答
0
用于NSTimer
设置更改标题的时间间隔。
在中添加以下行viewDidLoad
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(ChangeButtonText) userInfo:nil repeats:YES];
定时器触发时调用的函数。在这里更改按钮标题。将此方法复制到您的.m
文件中。
-(void)ChangeButtonText
{
if([_button.titleLabel.text isEqualToString:@"buttonName"])
{
[_button setTitle:@"" forState:UIControlStateNormalState];
}
else
{
[_button setTitle:@"buttonName" forState:UIControlStateNormalState];
}
}
于 2013-02-26T13:14:18.883 回答
0
这对我有用..
- (void)viewDidLoad
{
[super viewDidLoad];
[btn setTitle:@"Hello" forState:UIControlStateNormal];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(btnPress) userInfo:nil repeats:YES];
}
-(void)btnPress
{
if([btn.currentTitle isEqualToString:@"Hello"])
{
[btn setTitle:@"" forState:UIControlStateNormal];
}
else
[btn setTitle:@"Hello" forState:UIControlStateNormal];
}
于 2013-02-26T13:14:51.500 回答
0
您可以使用:
[button setTitle:@"text" forState:UIControlStateNormalState];
对于空:
[button setTitle:@"" forState:UIControlStateNormalState];
于 2013-02-26T13:07:47.747 回答