0

I am new in iOS development. I want to show UIButton text for 1 second, and show no text for another 1 second. Can any one tell me the logic in iOS?

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82

6 Answers6

1

Using NSTimer with regular TimeInterval of 1.0, change the text of UIButton

Madhu
  • 1,542
  • 1
  • 14
  • 30
1

Add this method to your .m file

- (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];
    }
}

and then in your viewDidLoad call the above method like this :

[self changeNameOfTheButton];
Ushan87
  • 1,608
  • 8
  • 15
0

you can use:

[button setTitle:@"text" forState:UIControlStateNormalState];

and for empty:

[button setTitle:@"" forState:UIControlStateNormalState];
Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64
0

Make use of NSTimer for setting the time interval to change the title.

Add the following line in viewDidLoad

 [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(ChangeButtonText) userInfo:nil repeats:YES];

Function which is called when timer triggers. Here change the button title. Copy this method to your .m file.

  -(void)ChangeButtonText
  {
   if([_button.titleLabel.text isEqualToString:@"buttonName"])
    {
        [_button setTitle:@"" forState:UIControlStateNormalState];

     }
   else
    {
       [_button setTitle:@"buttonName" forState:UIControlStateNormalState];

    }
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Vinayak Kini
  • 2,919
  • 21
  • 35
0

This works for me..

- (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];
}
Midas
  • 930
  • 2
  • 8
  • 20
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];
}
Bhanu Prakash
  • 1,493
  • 8
  • 20