我正在尝试找到一种方法来检测我的应用中的按钮文字。基本上,它是一个迷你应用程序商店。我有一个蓝色安装按钮,当它被轻敲,并变成绿色并说确认。 (就像iOS App Store一样。)有没有办法检测按钮何时显示文本“CONFIRM”,所以当它显示时点击它,链接会打开以安装应用程序?或者,另一种方法是检测按钮点击,但对我来说,没有任何方法可以帮助我。这是我目前的代码:
- (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
我使用以下代码找到了解决方案:
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]];
}