这个库受到UIAlertController的启发。TWAlertView将自动识别最顶层的视图控制器来显示警告,从而使显示简单的警告变得轻松简单。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[TWAlertView showAlert:@"Hello" message:@"What do you like to do today?" buttonsArray:[NSArray arrayWithObjects:@"Socialise",@"Code", nil] callback:^(NSError *error, int buttonIndex) {
if (error) {
NSLog(@"%@",error.debugDescription);
}else{
switch (buttonIndex) {
case 0:
[self socialise];
break;
case 1:
[self code];
break;
default:
break;
}
}
}];
return YES;
}
- (void)socialise{
[TWAlertView showAlert:@"Warning!" message:@"Are you sure you want to compromise your valuable time?"];
}
- (void)code{
[TWAlertView showAlert:@"Nice!" message:@"Good choice buddy"];
}
TWAlertView可通过CocoaPods获取。要安装,只需将以下行添加到您的Podfile文件中:
pod 'TWAlertView', '0.1.3'
TWAlertView遵循MIT许可证。更多信息请参阅LICENSE文件。