I am trying to find a way to detect the button text in my app. Basically, it is a mini app-store. I have a blue install button, and when it is tapped, and turns green and says confirm. (Like the iOS App Store.) Is there a way to detect when the button displays the text "CONFIRM" so when it is tapped when it says that, the link opens to install the app? Or, another way to do this would be to detect button taps, but nothing works for me in the way I'm trying to do this. Here is my current code:
- (IBAction)buttonDownload:(id)sender {
//in the storyboard file, the button is set to say "INSTALL"
[sender setTitle:@"CONFIRM" forState:UIControlStateNormal];
[sender setTitleColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
[[self.appInstallOutlet layer] setBorderColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0].CGColor];
//now, if the button displays "CONFIRM", open the link from a JSON file...
//Here is where the if statement should start...
NSString *linkForApp = [self.appDetails objectForKey:@"linkForApp"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: linkForApp]];
//end if statement
I have found a solution by using the following code:
UIButton *resultButton = (UIButton *)sender;
if ([resultButton.currentTitle isEqualToString: @"INSTALL"]) {
[sender setTitle:@"CONFIRM" forState:UIControlStateNormal];
[sender setTitleColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
[[self.appInstallOutlet layer] setBorderColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0].CGColor];
}
else if ([resultButton.currentTitle isEqualToString:@"CONFIRM"]) {
NSString *linkForApp = [self.restuarantDetail objectForKey:@"linkForApp"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: linkForApp]];
}